Scandalous weird old things about the C preprocessor (2015)
blog.robertelder.org
blog.robertelder.org
EDIT: Never mind, I'm wrong. Totally missed that line continuations can occur in quotes :(
char *cstr = "This \
#is a valid "
"C string";
If I understand you correctly, is this a counterexample?Sure, it can be be abused/misused but I am not sure that's a good reason to take it away completely like for example in C#.
#if LIB_VERSION_GE_3
lib_f (1, NULL);
#else
lib_f (1);
#endif
It can be difficult to do this with other mechanisms where the compiler is actually compiling and therefore type checking both branches.OCaml is a pretty rich language with many features, but we fall back on preprocessors like cppo (or even cpp) to deal with these kinds of cases.
Actually even in ISO C, the pre-processor is not required to be separated from the language, it is just kept that way in most compilers due to how C was originally implemented.
Even C++ is reducing the need to keep using the pre-processor with each ISO revision, in an ideal modern C++ world without C legacy baggage, the pre-processor will be so half assed like in C#. C++20 is already almost there.
It merely serves to alleviate an issue with a language limitation. And the library writers should have known better than to simply change the signature of an existing call.
(also this example reminds me of all the #ifndef/#define game that headers do which should have been built into the system in the first place)
I agree, unfortunately they do this and we have to cope with it.
#if constant-expression new-line group-opt
C99 6.10.1.2A major goal of D was to make the language expressive enough to not leave room for the preprocessor:
1. modules
2. manifest constants
3. nested functions
4. lambdas
5. static if
6. compile time function execution
7. string mixins
But you can go ahead and use this thread to promote D anyways.
#if 'z' - 'a' == 25
if ('z' - 'a' == 25)
Another difference is all constants are typed as intmax_t and uintmax_t, not the usual C types. Yes, it does have types.This difference in behavior from C expressions is not necessary.
If the OP is aggrieved by the operation of cpp, perhaps they could have explained in each of their points what cpp is doing wrong, and how they would improve the standard. Instead, they just list 'odd' behaviour, with no comment about why it is wrong and how it could be better.
Other languages whose designers were not pleased with C macros either avoided use of a preprocesor entirely, or, like c++, came up with alternative means of compile time flexibility. (Like templates)
* where I'm defining "bad-faith" C programmers as using it for sadistic purposes like IOCCC, golf, etc
> perhaps they could have explained in each of their points what cpp is doing wrong, and how they would improve the standard.
This is a fairly toxic attitude, and possibly the reason that your comment is unpopular. A child can correctly observe that an emperor is not wearing clothes, and bring that up without possessing the skill to make the emperor a suitable outfit.
At least the child told people that the emperor was wearing no clothes; a more apt analogy with this article would be as if the child merely said "that's scandalous!" without telling anyone about the missing clothes...
Here the "scandal" is that the "standard" is poorly specified, and therefore isn't much of a standard. This seems to be the root of the scandal, and all else appears to flow from here.
> 2) Context Free, Just Kidding!
Here the "scandal" is regarding to context sensitivity -- the author vacillates about the status of the "scandal" but still, it seems clear that they're identifying context-sensitivity as scandalous.
> 3) Whitespace Insensitive, Just Kidding!
Here the author considers irregularities in how "whitespace sensitive" cpp is -- both in the "spec" and in implementations, with an example of non-portability between gcc and clang.
et cetera
Not wearing clothes is what CPP does by default
And it's hardly an emperor, it's more the guy who makes copies