I was curious why you would return a value and not just make the main function return void (in the interests of simplicity and maintainability, and assuming you're using C not C++). So I wrote my own such program, and discovered that void main(void) returns 3 to the OS. Any ideas why?
I always thought it was a historical choice that simple substitution languages were simpler to implement so were chosen as a default.
It is kind of infuriating that the preprocessor always feels simultaneously _too powerful_ and _not powerful enough_ for the jobs you want to get done. I find myself reaching for other tools (kaitai, m4 etc) a lot more these days to take the role.
The kenc[1] compiler subsequent to K&R C had much more constrained macro system exactly for those reasons. Thanks to advances in optimization and improved machine speed, it was reasonable to skip preprocessor-level const operations. Thanks to dead code elimination it was feasible to mostly give up conditional compilation.
It's too bad the code examples have to be in C++. When I saw the prompt, it brought to mind the fabulous Shakespeare Programming Language, which would allow for a more poetic approach:
23 comments
[ 4.6 ms ] story [ 57.9 ms ] threadhttps://webcache.googleusercontent.com/search?q=cache:O9K6ou...
Oh, it works.
https://tio.run/#perl6
#include <stdio.h>
int main(void) { puts("42"); return 0; }
(Coz 42 is Gods phone #, duh...)
VROOMFONDEL: Or may not be
MAJIKTHISE: …or may not be… a god, if this machine comes along the next morning and gives you ‘is telephone number?
I love C but I will never understand why C has a naive macro system.
It is kind of infuriating that the preprocessor always feels simultaneously _too powerful_ and _not powerful enough_ for the jobs you want to get done. I find myself reaching for other tools (kaitai, m4 etc) a lot more these days to take the role.
[1] as used, for example, in Plan 9.
http://shakespearelang.sourceforge.net/report/shakespeare/sh...
42
[1] https://www.ioccc.org/2014/wiedijk/prog.c
[2] https://www.ioccc.org/2014/wiedijk/hint.html