42
The Most Beautiful Piece of Code That Prints 42
11–20 of 24 posts
Re: The Most Beautiful Piece of Code That Prints 42
#12Re: The Most Beautiful Piece of Code That Prints 42
#13#include #define SIX 1+5 #define NINE 8+1 int main(void) { printf("%d * %d = %d\n", SIX, NINE, SIX * NINE); return 0; } https://github.com/Keith-S-Thompson/42
Re: The Most Beautiful Piece of Code That Prints 42
#14#include #define SIX 1+5 #define NINE 8+1 int main(void) { printf("%d * %d = %d\n", SIX, NINE, SIX * NINE); return 0; } https://github.com/Keith-S-Thompson/42
I love C but I will never understand why C has a naive macro system.
Re: The Most Beautiful Piece of Code That Prints 42
#15Beautiful code is simple maintainable code. In C this is a simple as: #include int main(void) { puts("42"); return 0; }
Re: The Most Beautiful Piece of Code That Prints 42
#16#include #define SIX 1+5 #define NINE 8+1 int main(void) { printf("%d * %d = %d\n", SIX, NINE, SIX * NINE); return 0; } https://github.com/Keith-S-Thompson/42
#define SIX 1+8
#define NINE 5+1Re: The Most Beautiful Piece of Code That Prints 42
#17Beautiful code is simple maintainable code. In C this is a simple as: #include int main(void) { puts("42"); return 0; }
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?
Re: The Most Beautiful Piece of Code That Prints 42
#18#include #define SIX 1+5 #define NINE 8+1 int main(void) { printf("%d * %d = %d\n", SIX, NINE, SIX * NINE); return 0; } https://github.com/Keith-S-Thompson/42
Re: The Most Beautiful Piece of Code That Prints 42
#19#include #define SIX 1+5 #define NINE 8+1 int main(void) { printf("%d * %d = %d\n", SIX, NINE, SIX * NINE); return 0; } https://github.com/Keith-S-Thompson/42
Ever waste days debugging a subtle bug introduced by C macros? It's PTSD material. 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.
Re: The Most Beautiful Piece of Code That Prints 42
#20Like most code, this is way too easy in Perl 6. > perl6 -e 'say "Life, the Universe and Everything".WHY' 42