Main is usually a function. So then when is it not? (2015)
jroweboy.github.io
Main is usually a function. So then when is it not? (2015)
1–10 of 59 posts
Re: Main is usually a function. So then when is it not? (2015)
#2Re: Main is usually a function. So then when is it not? (2015)
#3After much experimentation, it turned out that the smallest program that would compile and run was only 5 bytes long:
main;
Re: Main is usually a function. So then when is it not? (2015)
#4Back when compiler warnings possibly cost extra processing time to generate, it was possible to make gcc compile the craziest things. After much experimentation, it turned out that the smallest program that would compile and run was only 5 bytes long: main;
In languages like Haskell you can just make 2+2=5: https://codegolf.stackexchange.com/a/28794
Re: Main is usually a function. So then when is it not? (2015)
#5Back when compiler warnings possibly cost extra processing time to generate, it was possible to make gcc compile the craziest things. After much experimentation, it turned out that the smallest program that would compile and run was only 5 bytes long: main;
> make gcc compile the craziest things In languages like Haskell you can just make 2+2=5: https://codegolf.stackexchange.com/a/28794
Re: Main is usually a function. So then when is it not? (2015)
#6__attribute__((section(".text"))
Re: Main is usually a function. So then when is it not? (2015)
#7 const int main[] __attribute__ ((section(".text"))) = {
-443987883, 440, 113408, -1922629632,
4149, 899584, 84869120, 15544,
266023168, 1818576901, 1461743468, 1684828783,
-1017312735
};
Compilation (gcc 13): $ gcc -Wall main.c -o main
main.c:1:11: warning: ‘main’ is usually a function [-Wmain]
1 | const int main[] __attribute__ ((section(".text"))) = {
| ^~~~
/tmp/ccsWmdiD.s: Assembler messages:
/tmp/ccsWmdiD.s:4: Warning: ignoring changed section attributes for .text
Execution: $ ./main
Hello World!Re: Main is usually a function. So then when is it not? (2015)
#8Back when compiler warnings possibly cost extra processing time to generate, it was possible to make gcc compile the craziest things. After much experimentation, it turned out that the smallest program that would compile and run was only 5 bytes long: main;
The craziest thing I got gcc (the AVR version, specifically) to compile for real purposes was a preprocessor macro that spit out tens of thousands of asm blocks with memory barriers and nop (do nothing) instructions with "PORTB = 1;" in the middle and "PORTB = 0" at the end. I needed it to bitbang out a clock signal to read an RFID tag on poorly documented hardware. (fun fact: the clock the cpu uses on an arduino uno is considerably worse and less accurate than the one that's on the board for the USB chip.)
Re: Main is usually a function. So then when is it not? (2015)
#9Why does the article say the problem would be tricky on 32-bit? `lea` is an old instruction. Thanks.
Re: Main is usually a function. So then when is it not? (2015)
#10The article says `lea` helps calculate the array relative address on AMD64. Why does the article say the problem would be tricky on 32-bit? `lea` is an old instruction. Thanks.
Btw, his code is wrong, it assumes pointers fit into 32 bits.