6 ms·
I'm not convinced this is a C89 program. It is only an "accident" that the linker doesn't know about types. I find it hard to believe that the C89 spec states
by jstanley 13y ago
I'm not convinced this is a C89 program. It is only an "accident" that the linker doesn't know about types.
I find it hard to believe that the C89 spec states that an integer called "main" is to be considered the main function, and suspect this is undefined behaviour (though I've not checked).
- poizan42 13y agoIt can't be a valid C89 program. On many Harvard architecture based microprocessors data pointers and code pointers have differing size.
- dietrichepp 13y agoDifferent size maybe, but different busses^H^H^H^H^H^Haddress spaces definitely, and using an address on the wrong bus is a sure way to cause problems.
- poizan42 13y agoOf course that is the definition of a Harvard architecture. It doesn't says that it won't link, just that it won't work. If compiling to an architecture with smaller sized code pointers than data pointers then the linker will most likely refuse to link it at all - otherwise it will have to truncate the adresses.
- kmm 13y ago^W will delete the previous word.
- mikeash 13y agoIs any crashing C program valid? You can only crash by invoking undefined behavior, and I believe that any program which invokes undefined behavior is "invalid". It's a major pitfall of C that determining "validity" requires solving the halting problem.
- nitrogen 13y agoIt compiles and runs with gcc -std=c89 and gcc -std=c99, so even if it's not a true C89 program, it's a compilable GNUC89 program. $ gcc -std=c99 -pedantic /tmp/main.c -o /tmp/main /tmp/main.c:1:1: warning: data definition has no type or storage class [enabled by default] /tmp/main.c:1:1: warning: type defaults to ‘int’ in declaration of ‘main’ [enabled by default] /tmp/main.c:1:1: warning: ‘main’ is usually a function [-Wmain] $ /tmp/main Segmentation fault (core dumped)
- kghose 13y agoNot on mac: a.c -> main; gcc -nostdlib -std=c89 a.c -o a a.c:1: warning: data definition has no type or storage class Undefined symbols for architecture x86_64: "start", referenced from: -u command line option ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status`