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
3 answers

How to check if a member name (variable or function) exists in a class, with or without specifying type?

This Q is an extension of: Templated check for the existence of a class member function? Is there any utility which will help to find: If a member name exists inside a class or not? This member can be a variable or a method. Specifying the type of…
iammilind
  • 68,093
  • 33
  • 169
  • 336
5
votes
4 answers

Evaluate macro parameter once only

In the following code, whatever is passed as retval is evaluated as given for every use of that token. #define _CPFS_RETURN(commit, retval) do { \ util_cpfs_exit(commit); \ return retval; \ } while (false) #define…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
5
votes
1 answer

How to determine when -fsanitize=memory is in use?

I want to clear a false positive on FD_ZERO and FD_SET when the memory sanitizer is in use. Clearing it is somewhat easy: #include ... __msan_unpoison(&readfds, sizeof(readfds)); __msan_unpoison(&writefds,…
jww
  • 97,681
  • 90
  • 411
  • 885
5
votes
3 answers

How to use macro arguments in call to another macro?

I'd like to be able to create a macro which calls other macros. The macro I'd like to call is the Benchmark macro from folly. Ultimately, I'd like to have a bunch of macros that look like: BENCHMARK(filter_10_vector_1_filter, n) { ...…
Paymahn Moghadasian
  • 9,301
  • 13
  • 56
  • 94
5
votes
2 answers

Why does this macro result in an unresolved name error?

I would like to compile code similiar to this minimal test case: macro_rules! why { ( [ $saved:ident ] $body:block ) => { let $saved = 3; $body let _a = $saved; } } fn bar() { why!([saved] { }); } fn main()…
5
votes
2 answers

Unnamed parameters in C

In C, unlike C++, all parameters to a function definition must be named. Instead of quashing "unused parameter" errors with (void)a, or openly using __attribute__((unused)), I've created the following macro: #define UNUSED2(var, uniq) UNUSED_ ##…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
5
votes
1 answer

what is the meaning of this C macro?

Here is a macro can calculate the count of arguments. and the code like: #define Y_TUPLE_SIZE_II(__args) Y_TUPLE_SIZE_I __args #define Y_TUPLE_SIZE_PREFIX__Y_TUPLE_SIZE_POSTFIX ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0 #define…
5
votes
1 answer

Detect OpenCL device vendor in kernel code

I'm writing some platform specific optimizations and while I'm aware of the fact that I could parse the vendor string in the host code and send that to the kernel using the -D option, it is perhaps more convenient to detect the vendor in the kernel…
the swine
  • 10,713
  • 7
  • 58
  • 100
5
votes
4 answers

What is the macro definition of isupper in C?

I want to know how the "isupper" macro is defined in C/C++. Could you please provide me the same or point me to available resources. I tried looking at ctype.h but couldnt figure it out.
josh
  • 13,793
  • 12
  • 49
  • 58
5
votes
3 answers

Scheme Macro for nesting expressions

Can a macro be written in Scheme (with define-syntax, for example) which will take expressions like this: (op a b c d e f g h i j) And yield expressions like this as output? (op (op (op (op (op (op (op (op (op a b) c) d) e) f) g) h) i) j) Of…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
5
votes
1 answer

Macroexpand for parenscript

Is there an equivalent to macroexpand or macroexpand-1 for parenscript macros? Doing (ps (some macro expression)) will display the generated javascript, but there are times when it would be nice to see the parenscript just before it gets converted…
BnMcGn
  • 1,440
  • 8
  • 22
5
votes
3 answers

C/C++ Passing Macros that take arguments on the compile line

I was wondering if it's possible to pass macros that take arguments on the compile line to gcc or other C/C++ compilers. I've never seen this before, but it would actually be useful for some of the OpenCL development that I've been doing where I…
Huarache
  • 246
  • 2
  • 13
5
votes
1 answer

Assembly-generating macros in common lisp

I'm interested in seeing how low-level a programmer can go in pure Common Lisp (or, failing that, in implementation-specific extensions). Google hasn't been able to find me much information about this, so I'd like to hear what the experts have to…
Reepca
  • 323
  • 2
  • 7
5
votes
0 answers

scala macros: local expand?

Can scala 2.11 macros force their parameters' macros to expand? Here's my use case: I started with the printf macro from the documentation and then made my own macro to concatenate strings. def mconcat(s1: String, s2: String, s3: String): String =…
Ben Greenman
  • 1,945
  • 12
  • 22
5
votes
2 answers

How to force processor to use result of expression before pasting

My code is #define PASTE__(a, b) a##b #define PASTE_(a, b) PASTE__(a, b) #define PASTE(a, b) PASTE_(a, b) int main() { PASTE(1, (1+3)/4); return 0; } I would LIKE to have the result be int main() { 11; return 0; } Compilable…
Bob
  • 4,576
  • 7
  • 39
  • 107
1 2 3
99
100