I thought it could be nice to introduce condition inside macro definition, to produce less jumping code (so compiler can output bigger but more efficient code with concise definition)
a syntax could be defined by adding an optional #defif (due to the late time this could be introduced to C, that would be my preference reminding to who would learn by seeing it that the if is part of the macro definition) as
#define macro(#N,x) #defif (#N>0) macro(#N-1,…) #defelse …
usable with macro(5,x)
On 1/9/22 7:52 PM, Marco Munari wrote:
I thought it could be nice to introduce condition inside macro
definition, to produce less jumping code (so compiler can output
bigger but more efficient code with concise definition)
a syntax could be defined by adding an optional #defif (due to the
late time this could be introduced to C, that would be my preference
reminding to who would learn by seeing it that the if is part of the
macro definition) as
#define macro(#N,x) #defif (#N>0) macro(#N-1,?) #defelse ?
usable with macro(5,x)
The committee decided long ago to not allow recursive macros. The
relevant wording is:
2 If the name of the macro being replaced is found during this scan of
the replacement list (not including the rest of the source file's preprocessing tokens), it is not replaced. Furthermore, if any nested replacements encounter the name of the macro being replaced, it is not replaced. These nonreplaced macro name preprocessing tokens are no
longer available for further replacement even if they are later
(re)examined in contexts in which that macro name preprocessing token
would otherwise have been replaced." (6.10.3.4p2).
The Rationale explains: "A problem faced by many pre-C89 preprocessors
is how to use a macro name in its expansion without suffering 'recursive death.' The C89 Committee agreed simply to turn off the definition of a macro for the duration of the expansion of that macro."
I thought it could be nice to introduce condition inside macro
definition, to produce less jumping code (so compiler can output
bigger but more efficient code with concise definition)
a syntax could be defined by adding an optional #defif (due to the
late time this could be introduced to C, that would be my preference reminding to who would learn by seeing it that the if is part of the
macro definition) as
#define macro(#N,x) #defif (#N>0) macro(#N-1,?) #defelse ?
usable with macro(5,x)
expansion parameter that i called #N need to be a constant provided
to the expansion engine, the # prefix I indicated here is not a
syntax necessity because it can be deduced by the fact that this
parameters appears in the #defif condition which also must be fully
valuable during preprocessing (just a bit more powerful
preprocessing) [...]
Marco Munari <aller...@gmail.com> writes:[I wrote this first post encountering the message
I thought it could be nice to introduce condition inside macro
definition, to produce less jumping code (so compiler can output
bigger but more efficient code with concise definition)
a syntax could be defined by adding an optional #defif (due to the
late time this could be introduced to C, that would be my preference reminding to who would learn by seeing it that the if is part of the
macro definition) as
#define macro(#N,x) #defif (#N>0) macro(#N-1,...) #defelse ...
usable with macro(5,x)
expansion parameter that i called #N need to be a constant provided
to the expansion engine, the # prefix I indicated here is not a
syntax necessity because it can be deduced by the fact that this parameters appears in the #defif condition which also must be fully valuable during preprocessing (just a bit more powerful
preprocessing) [...]
It's an interesting idea. There are details that need to be
explored and understood first. Also I think it would be better
if expanded and generalized, perhaps along the lines of 'cond'
in lisp, or alternatively with ?# :# as preprocessing if/else.
Hmmm...
On Monday, January 17, 2022 at 4:51:12 PM UTC+1, Tim Rentsch wrote:
Marco Munari <aller...@gmail.com> writes:
[conditional / recursive macro expansion]
It's an interesting idea. There are details that need to be
explored and understood first. Also I think it would be better
if expanded and generalized, perhaps along the lines of 'cond'
in lisp, or alternatively with ?# :# as preprocessing if/else.
Hmmm...
I'm favorable to any changes to the syntax I proposed,
You mentioned lisp, yes and why not lisp... I mean even lisp
syntax! [...]
Interesting also your concise syntax ?# :# (or maybe you
meant ... #? ... #: ... [...]
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 991 |
Nodes: | 10 (0 / 10) |
Uptime: | 81:10:32 |
Calls: | 12,949 |
Calls today: | 3 |
Files: | 186,574 |
Messages: | 3,264,663 |