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

Are spaces allowed after a backslash to continue a line (in C/C++)

When using \ to continue a line, are spaces allowed after the backslash (on the same line)?
Bob
  • 4,576
  • 7
  • 39
  • 107
5
votes
6 answers

Is it possible to set preprocessor macro in sln file and not in a project? (VS2008 c++)

I am maintaining a large codebase and some vcproj files are used in different solutions. Due to some horrendous configuration and dependencies it seems the best way to handle some build issues is to #ifdef the code but in order to do that I need to…
Tim
  • 20,184
  • 24
  • 117
  • 214
5
votes
2 answers

Macros evaluation in c programming language

Possible Duplicate: What does “#define STR(a) #a” do? #include #define f(a,b) printf("yes") #define g(a) #a #define h(a) g(a) int main() { printf("%s\n",h(f(1,2))); printf("%s\n",g(f(1,2))); } Can…
Jagan
  • 4,649
  • 19
  • 60
  • 70
5
votes
1 answer

Implicit currying in Scheme with syntax-rules?

Jeffrey Meunier has an implicit Curry macro here, which uses defmacro. I was wondering if someone has ever written this with syntax-rules?
Jay
  • 9,585
  • 6
  • 49
  • 72
5
votes
1 answer

How does C preprocessor actually work?

I made the code snippet simpler to explain // Example 1 #define sum2(a, b) (a + b) #define sum3(a, b, c) (sum2(a, sum2(b, c))) sum3(1, 2, 3) // will be expanded to ((1 + (2 + 3))) // Example 2 #define score student_exam_score #define…
Kevin Dong
  • 5,001
  • 9
  • 29
  • 62
5
votes
1 answer

How to access compile time cljs var metadata from a clj macro?

I'd like to construct a ClojureScript macro (executed/compiled via Clojure) that informs it's construction of a return form based on the static, compile-time metadata of a ClojureScript var argument. I understand it is possible to access…
metasoarous
  • 2,854
  • 1
  • 23
  • 24
5
votes
1 answer

What does it mean if macros in a Lisp are monadic?

In the Lux Language introduction we read: Unlike in most other lisps, Lux macros are monadic. The (Lux a) type is the one responsibly for the magic by threading Compiler instances through macros. Macros must have the Macro type and then be declared…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
5
votes
1 answer

Fibonacci function doesn't calculate properly

I've defined this macro #define FIB(n) (( 4 << n*(3+n))/((4 << (2*n)) - (2 << n) - 1))%(2 << n) and when I try to get an answer, doesn't work properly, by example if I call FIB(7),it gives me 0, that clearly is wrong. I tested this function in…
Natali Torres
  • 303
  • 1
  • 4
  • 13
5
votes
2 answers

Get typedef of current class

I'm currently using boost::intrusive_ptr together with my GUI classes. Although this is more or less a convenience question, is there a proper way to get the typename of the current class? The reason I'm asking is that I have a macro for typedef'ing…
Sebastian Graf
  • 3,602
  • 3
  • 27
  • 38
5
votes
1 answer

Access Class of Context.getLocalClass() in build macro

I want to make a macro that adds a field to my classes, and the field value should be Class of class they are sitting in. Here is my minimal example, and it does not compile with this error: src/Base.hx:3: characters 2-11 : Unknown identifier :…
romamik
  • 595
  • 2
  • 9
5
votes
3 answers

Macro that unrolls a 'for' loop in racket/scheme?

I'm trying to write a macro in racket/scheme that operates like a for loop across some arbitrary code such that the body of the loop is unrolled. For example, the following code (macro-for ((i '(0 1 2 3)) (another-macro (with i) (some…
gablin
  • 4,678
  • 6
  • 33
  • 47
5
votes
1 answer

Difficulty in understanding the offsetof MACRO

I have been searching very long and hard (links at the very end) for an explanation of the implementation of the offsetof MACRO : #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) Particularly, the dereferencing of NULL to obtain the…
maverick
  • 63
  • 5
5
votes
1 answer

How to pass an Array of Expr (expressions) to Haxe Macro?

I'm basically trying to create a macro that automatically generates an if/else if chain by supplying one common outcome statement for all conditions. This is what I've tried so far (modified the code just to show as an example): import…
chamberlainpi
  • 4,854
  • 8
  • 32
  • 63
5
votes
1 answer

Why does macro hygiene not prevent collisions between multiple const definitions?

I thought "hygiene" would prevent collisions between Xs defined within my macro m! but that turned out not to be the case. What am I misunderstanding? macro_rules! m { ($e:expr) => { const X: i32 = $e; }; } m!(0); m!(1); fn main()…
nodakai
  • 7,773
  • 3
  • 30
  • 60
5
votes
2 answers

Macro in visual Studio 2010 that loads settings file

I'm just looking for a way (maybe a macro?) to load a settings file. Ideally I'd like to be able to run this as a shortcut from the desktop too. I googled it, but maybe I didn't hit the right keywords.
roundcrisis
  • 17,276
  • 14
  • 60
  • 92