Main is usually a function. So then when is it not? (2015)
51–59 of 59 posts
Re: Main is usually a function. So then when is it not? (2015)
#52With the right flags: `main;` (implicitly a zeroed int).
Re: Main is usually a function. So then when is it not? (2015)
#53Earlier quoted context omitted.
how about before anything is executed, add a parse step that reads the whole file, looks for function definitions, and then goes back to the start to execute?
What counts as a function definition? def a(): b() a() import random with open("max", "r") as f: m = int(f.read()) b = (lambda: "foo") if int(input("Pick a number: ")) % m > random.randint(0, m) else None
Re: Main is usually a function. So then when is it not? (2015)
#54Earlier quoted context omitted.
how about before anything is executed, add a parse step that reads the whole file, looks for function definitions, and then goes back to the start to execute?
What counts as a function definition? def a(): b() a() import random with open("max", "r") as f: m = int(f.read()) b = (lambda: "foo") if int(input("Pick a number: ")) % m > random.randint(0, m) else None
it becomes problematic if a function definition is conditional. i suppose then that the compilation should fail because i guess conditional definitions would not be covered.
Re: Main is usually a function. So then when is it not? (2015)
#55Back 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;
Welp that's a nerd snipe if I ever had one. Will report back once my bruteforce hack finishes crunching away.
Re: Main is usually a function. So then when is it not? (2015)
#56This is fun. On a broader note though, entry point main-type functions have always bothered me. Maybe because I grew up as a simple script kiddie with BASIC and Bash and PHP. I like code that starts executing from the first line and then runs whatever functions it wants to run. I realize that's just an abstraction of main() but it's a pleasant one for me. There's something more constricting about there being one func…
> There's something more constricting about there being one function to bootstrap everything than there is about one file. As a compiler author, there are a bunch of nasty surprises to this approach. If you execute a file line-by-line, then functions only exist once you "reach" them. If you write: def a(): b() a() def b(): ... ...then a() needs to crash when first called, because b() hasn't been declared yet. So your…
Re: Main is usually a function. So then when is it not? (2015)
#57Earlier quoted context omitted.
Welp that's a nerd snipe if I ever had one. Will report back once my bruteforce hack finishes crunching away.
Please do, I'm eager to find out how long it takes to compile and run 4,294,967,296 small C files on modern hardware ;)
But ultimately I gave up after the third time my computer crashed. I was at length 4 by that point, next step would have been to throttle the CPU usage.
Re: Main is usually a function. So then when is it not? (2015)
#58Earlier quoted context omitted.
> make gcc compile the craziest things In languages like Haskell you can just make 2+2=5: https://codegolf.stackexchange.com/a/28794
That’s not that crazy. It just shadows the global + function. And thanks to lexical scope it has a rather limited impact.
Re: Main is usually a function. So then when is it not? (2015)
#59Earlier quoted context omitted.
I still get a segmentation fault out of that when I run it. I think there's flags you can use to get the linker to not complain about missing main if you give gcc an empty file. 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 m…
Must be the internal RC clock? it sucks.
It's enough to work for most things. Only annoying thing is, if you use the ICSP header to set the clock to external, you need a working clock to even use ICSP. (the 328pb falls back to the internal clock in this case)