I wept when the author mentioned implementing SHA256 in macros.
Recursive macros in C, demystified (once the ugly crying stops)
41–50 of 90 posts
Re: Recursive macros in C, demystified (once the ugly crying stops)
#42Mildly related, sort of, one can prevent expansion of variadic macros as follows: #define printf(...) int (printf)(const char *, ...); I keep on seeing many random code bases just resort to #undef instead...
Re: Recursive macros in C, demystified (once the ugly crying stops)
#43Re: Recursive macros in C, demystified (once the ugly crying stops)
#44In many ways being limited ends up being a feature. Even limited as it is, you get some crimes against humanity like the bourne shell source, but at least most people agree it is a bad idea If it allowed more unlimited metaprogramming, building big complex things as macros might well have become popular
Re: Recursive macros in C, demystified (once the ugly crying stops)
#45Mildly related, sort of, one can prevent expansion of variadic macros as follows: #define printf(...) int (printf)(const char *, ...); I keep on seeing many random code bases just resort to #undef instead...
Doesn't this trigger warnings?
Re: Recursive macros in C, demystified (once the ugly crying stops)
#46Re: Recursive macros in C, demystified (once the ugly crying stops)
#47The behavior of C macros is actually described by a piece of pseudocode from Dave Prosser and it is not in the standard: * https://www.spinellis.gr/blog/20060626/ * https://www.spinellis.gr/pubs/jrnl/2006-DDJ-Finessing/html/S... * https://gcc.gnu.org/legacy-ml/gcc-prs/2001-q1/msg00495.html
Wow, I'm not sure I've ever seen this (or if I did, it was 20 years ago). And I was definitely looking around for this kind of history when I was searching around when writing. Perhaps my google skills have decayed... or google... or both! Thanks very much.
Re: Recursive macros in C, demystified (once the ugly crying stops)
#48 _ Pure macros as a programming language
_
_ m4 is Turing complete even when stripped to the bare minimum
_ of one builtin: `define'. This is not news; Christopher
_ Strachey demonstrated it in his ancestral GPM, described in
_ "A general- purpose macrogenerator", The Computer Journal 8
_ (1965) 225-241.
_
_ This m4 program more fully illustrates universality by
_ building familiar programming capabilities: unlimited
_ precision integer arithmetic, boolean algebra, conditional
_ execution, case-switching, and some higher-level operators
_ from functional programming. In support of these normal
_ facilities, however, the program exploits some unusual
_ programming idioms:
_
_ 1. Case-switching via macro names constructed on the fly.
_ 2. Equality testing by redefining macros.
_ 3. Representing data structures by nested parenthesized lists.
_ 4. Using macros as associative memory.
_ 5. Inserting nested parameter symbols on the fly.
_
_ Idioms 2 and 5 are "reflective": the program writes code
_ for itself.
It's very easy to get into enormous amounts of trouble in m4, m6, or GPM. The C preprocessor is not without its problems, but it is rare that I have difficulty in understanding why a given gcc -E invocation produces the output it does.Re: Recursive macros in C, demystified (once the ugly crying stops)
#49The behavior of C macros is actually described by a piece of pseudocode from Dave Prosser and it is not in the standard: * https://www.spinellis.gr/blog/20060626/ * https://www.spinellis.gr/pubs/jrnl/2006-DDJ-Finessing/html/S... * https://gcc.gnu.org/legacy-ml/gcc-prs/2001-q1/msg00495.html