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
1805
votes
5 answers

What is ':-!!' in C?

I bumped into this strange macro code in /usr/include/linux/kernel.h: /* Force a compilation error if condition is true, but also produce a result (of value 0 and type size_t), so the expression can be used e.g. in a structure initializer (or…
chmurli
  • 15,080
  • 3
  • 16
  • 12
355
votes
15 answers

What makes Lisp macros so special?

Reading Paul Graham's essays on programming languages one would think that Lisp macros are the only way to go. As a busy developer, working on other platforms, I have not had the privilege of using Lisp macros. As someone who wants to understand the…
minty
  • 22,235
  • 40
  • 89
  • 106
306
votes
6 answers

Strange definitions of TRUE and FALSE macros

I have seen the following macro definitions in a coding book. #define TRUE '/'/'/' #define FALSE '-'-'-' There was no explanation there. Please explain to me how these will work as TRUE and FALSE.
Keshava GN
  • 4,195
  • 2
  • 36
  • 47
298
votes
2 answers

how to use #ifdef with an OR condition?

Sorry for asking very basic question. I would like to set OR condition in #ifdef directive.? How to do that ? I tried #ifdef LINUX | ANDROID ... .. #endif It did not work? What is the proper way?
Whoami
  • 13,930
  • 19
  • 84
  • 140
244
votes
10 answers

Overloading Macro on Number of Arguments

I have two macros FOO2 and FOO3: #define FOO2(x,y) ... #define FOO3(x,y,z) ... I want to define a new macro FOO as follows: #define FOO(x,y) FOO2(x,y) #define FOO(x,y,z) FOO3(x,y,z) But this doesn't work because macros do not overload on number of…
Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
226
votes
1 answer

C multi-line macro: do/while(0) vs scope block

Possible Duplicates: What’s the use of do while(0) when we define a macro? Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? do { … } while (0) what is it good for? I've seen some multi-line C macros that are…
krasnaya
  • 2,995
  • 3
  • 21
  • 19
212
votes
31 answers

__FILE__ macro shows full path

The standard predefined macro __FILE__ available in C shows the full path to the file. Is there any way to shorten the path and get just the filename? I mean instead of /full/path/to/file.c I see to/file.c or file.c
mahmood
  • 23,197
  • 49
  • 147
  • 242
205
votes
6 answers

Saving vim macros

Does anyone know how to properly save/reuse macros recorded inside of a vim editor?
jnadro52
  • 3,454
  • 3
  • 21
  • 17
205
votes
10 answers

Can I record/play macros in Visual Studio 2012/2013/2015/2017/2019?

Apparently macros were dropped from Visual Studio 2012. Is there a plugin/extension/tool that will let me record & play keyboard macros (much like the record/play temporary macro in Visual Studio 2010)? For example, I typically would use a macro…
190
votes
14 answers

How do I show the value of a #define at compile-time?

I am trying to figure out what version of Boost my code thinks it's using. I want to do something like this: #error BOOST_VERSION but the preprocessor does not expand BOOST_VERSION. I know I could print it out at run-time from the program, and I…
Jim Hunziker
  • 14,111
  • 8
  • 58
  • 64
189
votes
5 answers

What does "#pragma comment" mean?

What does #pragma comment mean in the following? #pragma comment(lib, "kernel32") #pragma comment(lib, "user32")
user198729
  • 61,774
  • 108
  • 250
  • 348
182
votes
1 answer

Getting a structural type with an anonymous class's methods from a macro

Suppose we want to write a macro that defines an anonymous class with some type members or methods, and then creates an instance of that class that's statically typed as a structural type with those methods, etc. This is possible with the macro…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
176
votes
70 answers

What is the worst real-world macros/pre-processor abuse you've ever come across?

What is the worst real-world macros/pre-processor abuse you've ever come across (please no contrived IOCCC answers *haha*)? Please add a short snippet or story if it is really entertaining. The goal is to teach something instead of always telling…
Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
156
votes
2 answers

Is #pragma once part of the C++11 standard?

Traditionally, the standard and portable way to avoid multiple header inclusions in C++ was/is to use the #ifndef - #define - #endifpre-compiler directives scheme also called macro-guard scheme (see code snippet below). #ifndef…
101010
  • 41,839
  • 11
  • 94
  • 168
152
votes
6 answers

What does the Q_OBJECT macro do? Why do all Qt objects need this macro?

I just started using Qt and noticed that all the example class definitions have the macro Q_OBJECT as the first line. What is the purpose of this preprocessor macro?
Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
1
2 3
99 100