Passing c blocks to pre processor
Yair Lenga
yair.lenga@gmail.com
Sat May 28 05:48:31 GMT 2022
Hi,
I am trying to define macros that will accept code blocks. This will be used to create high level structures (like iterations, etc.). Ideally, I would like to do something like (this is simplified example, actual code much more application specific):
Foreach(var, low, high, block)
While should translate to:
For (int var=low ; var < high ; var ++) block
The challnge is the gcc pre processor does not accept blocks. It assume a comma terminate a block. For example:
Foreach(foo, 1, 30, { int z=5, y=3, …}) will invoke the macro with 5 arguments: (1) foo (2) 1, (3) 30, (4) { int z=5}, (5) y=3,
Is there a way to tell CPP that an argument that start with ‘{‘ should extend until the matching ‘}’ ? Similar to the way ‘(‘ in macro arguments will extend till matching ‘)’.
Thanks, yair.
Sent from my iPad
More information about the Gcc
mailing list