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
117
votes
10 answers

How can I convert from degrees to radians?

I am trying to convert this Obj-C code to Swift code but I don't know what the equivalent of this code should be ? #define DEGREES_TO_RADIANS(degrees)((M_PI * degrees)/180) I googled and found this But I don't understand how to convert that in…
Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
115
votes
9 answers

Is there a macro recorder for Eclipse?

Is there a good Eclipse plugin for recording and playing back macros? I've tried this one, but it didn't do me any good- it seemed like it wasn't ready for prime time. I know about editor templates, but I'm looking for something that I can use to…
Tim Howland
  • 7,919
  • 4
  • 28
  • 46
111
votes
13 answers

iOS How to detect iPhone X, iPhone 6 plus, iPhone 6, iPhone 5, iPhone 4 by macro?

How to detect device model by macro? i had using something like this but the result on the simulator alway IS_IPHONE_5 #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() ==…
phuongho
  • 1,147
  • 2
  • 9
  • 15
106
votes
9 answers

How can I define a string literal on the GCC command line?

On the GCC command line, I want to define a string such as -Dname=Mary. Then in the source code, I want printf("%s", name); to print Mary. How could I do it?
richard
  • 1,607
  • 6
  • 15
  • 18
102
votes
5 answers

replay a vim macro until end of buffer

I want to run a macro I just recorded in register "x" on every single line of an open buffer, from my cursor to end of the buffer, in vim. How do I do that? I know I can replay the macro n times: 15@x ...or just hold down @ until I reach the the…
Kevin
  • 1,170
  • 2
  • 8
  • 10
99
votes
3 answers

Vim Macro on Every Line of Visual Selection

I'd like to run a macro on every line in a selection, rather than totalling up the number of lines in my head. For instance, I might write a macro to transform: Last, First Into First Last and I'd like it to run on all these lines: Stewart, John…
Stefan Mai
  • 23,367
  • 6
  • 55
  • 61
96
votes
7 answers

Why only define a macro if it's not already defined?

All across our C code base, I see every macro defined the following way: #ifndef BEEPTRIM_PITCH_RATE_DEGPS #define BEEPTRIM_PITCH_RATE_DEGPS 0.2f #endif #ifndef BEEPTRIM_ROLL_RATE_DEGPS #define BEEPTRIM_ROLL_RATE_DEGPS …
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
92
votes
7 answers

How to view C preprocessor output?

How do I view the output produced by the C pre-processor, prior to its conversion into an object file? I want to see what the MACRO definitions do to my code.
user191776
89
votes
5 answers

What's the significance of a C function declaration in parentheses apparently forever calling itself?

In gatomic.c of glib there are several function declarations that look like this: gboolean (g_atomic_int_compare_and_exchange_full) (gint *atomic, gint oldval, gint…
Andreas
  • 9,245
  • 9
  • 49
  • 97
87
votes
8 answers

Real-world use of X-Macros

I just learned of X-Macros. What real-world uses of X-Macros have you seen? When are they the right tool for the job?
Agnius Vasiliauskas
  • 10,935
  • 5
  • 50
  • 70
83
votes
2 answers

What's the point of a PROTOTYPE macro that merely expands to its arguments?

I have a header file which contains #define PROTOTYPE(s) s What is the point of that? Seems like it would just replace the input with itself. There are TONS of other directives around it, but the only one that appears to have any bearing just…
Charlie Elverson
  • 1,180
  • 8
  • 18
83
votes
1 answer

What is PRIu64 in C?

I am new to C and I am confronted with: #include #include int main(void) { uint64_t foo = 10; printf("foo is equal to %" PRIu64 "!\n", foo); return 0; } And it works! I don't understand why. Can somebody…
torr
  • 1,256
  • 3
  • 11
  • 20
82
votes
18 answers

What are C macros useful for?

I have written a little bit of C, and I can read it well enough to get a general idea of what it is doing, but every time I have encountered a macro it has thrown me completely. I end up having to remember what the macro is and substitute it in my…
Jack Ryan
  • 8,396
  • 4
  • 37
  • 76
81
votes
9 answers

C# Macro definitions in Preprocessor

Is C# able to define macros as is done in the C programming language with pre-processor statements? I would like to simplify regular typing of certain repeating statements such as the following: Console.WriteLine("foo");
cl123
81
votes
3 answers

Understanding the behavior of C's preprocessor when a macro indirectly expands itself

While I was working on a big project full of macro tricks and wizardry, I stumbled upon a bug in which a macro was not expanding properly. The resulting output was "EXPAND(0)", but EXPAND was defined as "#define EXPAND(X) X", so clearly the output…
Luiz Martins
  • 1,644
  • 10
  • 24