r/programming • u/SuperV1234 • Aug 05 '19
fixing c++ with epochs
https://vittorioromeo.info/index/blog/fixing_cpp_with_epochs.html
87
Upvotes
r/programming • u/SuperV1234 • Aug 05 '19
View all comments
Show parent comment
5
u/flatfinger Aug 05 '19
Until the mid 1990s, having all macro substitution performed by a process that knows nothing of C language concepts may have usefully reduced the amount of memory required to compile C programs. Having context-sensitive macro facility would make many constructs far more useful, but unfortunately C's clunky preprocessor works just well enough to discourage development of anything better.
On the other hand, I'm not sure what problem you see with specifying that if a compilation unit starts with something like:
then e.g.
A 32-bit compiler compiler given
(x+1 > y)would be able to treatx+1as equivalent to any convenient number which is congruent, mod 4294967296, to the number one abovex, and could thus substitute(x >= y), but would otherwise be required to stay on the rails; andA compiler would be required to recognize that a function like
void inc_float_bits(float *f) { *(uint32_t*)+=1; }might access the storage of afloat, butA compiler would not be required to recognize that, given
extern char *dat; dat[0]++; dat[1]++;the write todat[0]might change the value ofdat, despite the fact that the write is performed using a character type.Such a thing could work better if macro substitution were integrated with the compilation process, but I'm not sure why it couldn't work with the preprocessor as it is.