Questions tagged [macros]

A macro in computer science is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to a replacement output sequence (also often a sequence of characters) according to a defined procedure. Do not use this tag for questions regarding Microsoft's Visual Basic for Applications.[Tag:vba] evolved from an early macro language, but is not a macro language.

Filter by
Sorted by
Tagged with
7
votes
4answers
3k views

'do { statement; } while(0)' against 'statement' when writing C macro? [closed]

Which one of the following is preferrable and why when writing C macro? Type 1 #define I2C_START() I2C_WAIT_IDLE(); SSP1CON2bits.SEN = 1 Type 2 ...
3
votes
2answers
438 views

scope_exit macro

This is actually not something new, but I think many people wanted something useful and not incredibly complicated. So, here it is: ...
6
votes
5answers
1k views

Macro for allocation in C

As we all know, the syntax of allocating memory is a bit clunky in C. The recommended way is: int *p; int n=10; p = malloc(n*sizeof *p); You can use ...
2
votes
0answers
50 views

Simple generic macro-generated containers

In order to learn macros in C I decided to make a generic data structures generator for other projects that I have in C. The main macros are the following: ...
17
votes
3answers
10k views

Generic C++ exception catch handler macro

I have this set of legacy C++ projects with a large number of public functions. At the start, none of those publicly exposed functions had try..catch insulation ...
16
votes
2answers
432 views

Formatted print without the need to specify type matching specifiers using _Generic

This code allows printing in C with a style similar to C++ ostream. By using _Generic() (see ...
9
votes
5answers
719 views

Resolving a link - follow-up

Similar piece of code to that I recently posted as: Resolving a link I have another piece of code which cannot be as easily extracted out into a method: ...
5
votes
3answers
157 views

Encapsulating snprintf to avoid repetition of sizeof

Correct usage of snprintf involves very long and repetitive lines: ...
3
votes
2answers
1k views

C try/catch macros

I've created simple try/catch macros that now I'd like to promote to wider use in my projects. I would have really liked to be able to do without global variables but I have not found any way to do ...
5
votes
1answer
127 views

Autotools detect YAML library

I have been updating my build tools to optionally use autotools (autoconfig/automake/libtool etc.). As part of this change I have written a couple of M4 macros. This not being something I have done ...
4
votes
1answer
187 views

Is this a good way to implement let-with?

I've implemented a let-with macro that takes an association list, keyed by symbols, that enables code to bind their corresponding values to local variables. It's ...
3
votes
0answers
75 views

Allowing switching between operator[] and at() based on NDEBUG macro version

The problem: std::vector and other containers have two functions for accessing / modifying their content: operator[] and ...
2
votes
1answer
105 views

Generic Macro Generated Linked List in C

Generate a linked list of any type using macros. The linked list contains functions for adding and removing elements to both ends and also at the middle. You can also add elements relatively to a list ...
-1
votes
1answer
188 views

Increase the execution speed of VBA macro code

I am providing you with the code of my macro and hope that somebody can tell me what is making my macro slow and provide me with a solution as to how to make it run faster. Currently the execution of ...