Questions tagged [macros]

***DO NOT USE for VBA / MS-Office languages. Use [vba] instead.*** A macro is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to an output sequence (also often a sequence of characters) according to a defined procedure.

A macro is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to an output sequence (also often a sequence of characters) according to a defined procedure. The mapping process that instantiates (transforms) a macro into a specific output sequence is known as macro expansion.

Wikipedia Article for Macro

'Macros' created in VBA/MS-Office applications, while sharing the same name, are not the same concept as defined here. Questions relating to VBA should be tagged and the respective Office-Product, e.g. , . Please see the tag wiki entry page for more information regarding proper usage.

Similarly, questions relating to other macro programming languages should not use this tag.

13505 questions
5
votes
1 answer

C89 determine size of int at preprocessor time

I want to compile code conditionally depending on the size of an integer, but I didn't quite find a way to determine the size of an integer in the preprocessor stage. One idea is using the INT_MAX and comparing it to a constant: #if INT_MAX >=…
FSMaxB
  • 2,280
  • 3
  • 22
  • 41
5
votes
3 answers

How can I schedule a Macro to run automatically in Access 2007

I'd like to have a macro, called Macro1, for example, run every day at 9 AM. It works great on its own from the VB code editor in Access 2007 but I would like it to be able to execute automatically without access being open. Please note that I don't…
alexcoco
  • 6,657
  • 6
  • 27
  • 39
5
votes
3 answers

Passing compile-time state between nested macros in Clojure

I'm trying to write a macro that can be used both in a global and nested way, like so: ;;; global: (do-stuff 1) ;;; nested, within a "with-context" block: (with-context {:foo :bar} (do-stuff 2) (do-stuff 3)) When used in the nested way,…
Oliver
  • 279
  • 2
  • 8
5
votes
2 answers

Ordering macro argument execution

I'm using a library for string interning (string-cache), that uses macros to efficient create elements (atom!). However for simplification here is a similar macro that demonstrates the problem macro_rules! string_intern { ("d") => ("Found…
Daniel Fath
  • 16,453
  • 7
  • 47
  • 82
5
votes
2 answers

VIM prompting for a variable when running a macro?

I find I waste a lot of time closing and reopening sets of files so I'd like to improve my VIM macro for loading and saving the session to support multiple sessions. I'd like for it to prompt for a string value, so that I could press my shortcut,…
user58777
5
votes
2 answers

Racket macro that defines multiple top-level forms?

I found myself defining syntax parameters with identical definitions except for their name so I decided to write a macro to make this simpler: (define-syntax (test-case-parameter stx) (syntax-parse stx [(_ parameter:id) …
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
5
votes
2 answers

Why does not Clojure support private functions in macro?

I was trying to implement xor macro and came up with a problem. I couldn't use private function in a macro. Here is the example: private function (defn :^private xor-result [x y] (if (and x y) false (or x y))) macro (defmacro xor ([]…
Ertuğrul Çetin
  • 5,131
  • 5
  • 37
  • 76
5
votes
1 answer

How can a macro definition be passed as an argument to make?

I wish to define a C macro by passing it as an argument to make, which is called from the command-line. Background: I want the directive #define ENABLE_OPT 1 to be included in my C source code when a certain build option is chosen. Thus, I want…
Anupama G
  • 311
  • 2
  • 11
5
votes
1 answer

Is there an equivalent of DoEvents in Visual Studio macros?

I've got a long-running macro, in which I write periodic messages to Output just so that the user know somethings happening. The problem is that the output doesn't get shown until the macro has finished (unless you have the Continue Waiting? dialog…
Benjol
  • 63,995
  • 54
  • 186
  • 268
5
votes
3 answers

Embedded C function macro problem

I came across this in embedded hardware using C. #define EnterPWDN(clkcon) ( (void (*)(int))0xc0080e0 ) (clkcon) I have no idea how is this function macro working. I understand clkcon is the function parameter to EnterPWDN, but what is happening…
zengr
  • 38,346
  • 37
  • 130
  • 192
5
votes
2 answers

Is there anyway to use for loop with string macro?

I have the following defines: #define STRING_OBJECT_1 "bird" #define STRING_OBJECT_2 "dog" #define STRING_OBJECT_3 "cat" #define STRING_OBJECT_4 "human" #define STRING_OBJECT_5 "cow" #define STRING_OBJECT_6 "snake" #define STRING_OBJECT_7…
JongHyeon Yeo
  • 879
  • 1
  • 10
  • 18
5
votes
1 answer

Is a repeated macro invocation via token concatenation unspecified behavior?

The C11 standard admits vagueness with regard to at least one situation that can arise in macro expansion, when a function like macro expands to its unenvoked name, and is invoked by the next preprocessing token. The example given in the standard is…
Kyle
  • 878
  • 6
  • 14
5
votes
1 answer

Ascending Numbers in Macro Definition

I frequently use Racket's pattern-matching construct match, and I thought a way to help myself with debugging programs using match, and to learn how Racket/Scheme macros work, would be to create a macro that includes information like which pattern…
user1017523
5
votes
2 answers

How to use valgrind with a function that is actually the expansion of a macro

Let's start with an example, I think this will demonstrate the problem I am dealing with immediately. This is a simple test program, far from realistic but it does illustrate the problem very well 1 #include 2 #include
Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
5
votes
2 answers

When to use macros functions in Erlang?

I'm currently following the book Learn You Some Erlang for Great Good by Fred Herbert and one of the sections is regarding Macros. I understand using macros for variables (constant values, mainly), however, I don't understand the use case for macros…
carbon_ghost
  • 1,114
  • 5
  • 18
  • 40