This reminds me of "A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux" [1]. The author tries to create the smallest possible elf executable possible. You would think it'd be easy... :) go read it. Very cool! [1] http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...
The Shortest Crashing C Program
81–90 of 94 posts
Re: The Shortest Crashing C Program
#82Who says it will crash? Could run very nicely, printing a list of prime numbers, or write poetry, or anything else that undefined behaviour encompasses.
"global variables in C are initialized to zero implicitly" NULL pointers will lead to a crash. It would be more interesting to have it as a random pointer, which could do quite anything.
Not in C. Dereferencing a NULL pointer is undefined behavior, so any of the actions described by the parent would be correct.
Re: The Shortest Crashing C Program
#83Earlier quoted context omitted.
It can't be a valid C89 program. On many Harvard architecture based microprocessors data pointers and code pointers have differing size.
Different 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.
Re: The Shortest Crashing C Program
#84Earlier quoted context omitted.
A bad hosting strikes again.
I have bad hosting with good software. Ran flawlessly with 8-15ms generation times on #3 of the HN homepage for a couple hours, only the network latency went up to at peak ~1.2 seconds (got less than 1mbps upload here). The page also executes multiple database queries for each pageload, just like Wordpress. No caching needed for me, it's all about optimization.
Re: The Shortest Crashing C Program
#85Earlier quoted context omitted.
I have bad hosting with good software. Ran flawlessly with 8-15ms generation times on #3 of the HN homepage for a couple hours, only the network latency went up to at peak ~1.2 seconds (got less than 1mbps upload here). The page also executes multiple database queries for each pageload, just like Wordpress. No caching needed for me, it's all about optimization.
What software do you use?
As for software, I wrote it for PHP 5.3 (nowadays upgraded to 5.4 though) with MySQL and persistent database connections. The server is Windows 7 with apache 2.4.
Re: The Shortest Crashing C Program
#86It depends on the definition. You can do better than this if you define a valid C program as anything that passes though the C compiler and generates an executable. Behold the zero length program: $ touch a.c $ gcc -c a.c $ ld a.o ld: warning: cannot find entry symbol _start; defaulting to 0000000000400078 $ ./a.out Segmentation fault
Re: The Shortest Crashing C Program
#87Earlier quoted context omitted.
A bad hosting strikes again.
I have bad hosting with good software. Ran flawlessly with 8-15ms generation times on #3 of the HN homepage for a couple hours, only the network latency went up to at peak ~1.2 seconds (got less than 1mbps upload here). The page also executes multiple database queries for each pageload, just like Wordpress. No caching needed for me, it's all about optimization.
Re: The Shortest Crashing C Program
#88Earlier quoted context omitted.
"global variables in C are initialized to zero implicitly" NULL pointers will lead to a crash. It would be more interesting to have it as a random pointer, which could do quite anything.
> NULL pointers will lead to a crash. Not in C. Dereferencing a NULL pointer is undefined behavior, so any of the actions described by the parent would be correct.
Re: The Shortest Crashing C Program
#89Earlier quoted context omitted.
> NULL pointers will lead to a crash. Not in C. Dereferencing a NULL pointer is undefined behavior, so any of the actions described by the parent would be correct.
Is 0 really the same thing the sane thing as 'NULL' in the context of C? If you actually wanted a pointer to the begging of the memory, you would dereference 0, which has the well defined meaning of getting whatever is at memory address 0. When the programming attempts to get that, it is shut down by the system.
Yes. I don't have chapter and verse handy but it is in the standard. The bit pattern of NULL is not required to be zero (so memset(&p, 0, sizeof(p)) is not guaranteed to yield null) but it must compare equally to 0 and assigning 0 must produce NULL.
[Edit: OK, in C99 this is covered in 6.3.2.3: Pointers. "An integer constant expression with the value 0, or such an expression cast to type void * , is called a null pointer constant." Then 7.17.3 says that NULL expands to a null pointer constant.]
> If you actually wanted a pointer to the begging of the memory, you would dereference 0,
Yeah, it's really easy to set up an environment where that happens. At one point I was experimenting with writing a small/toy kernel for x86 and I mapped the virtual address 0 to a valid page, and boom, dereferencing NULL did stuff. Not a great idea to set up the page tables that way for obvious reasons, but I'm going to guess that lots of hardware out there will let you do it...
In the old days of 16-bit x86, linear address 0 had the interrupt vector, so as I recall lots of DOS (maybe even Win9x) environments had dereferencing NULL do meaningful (surely confusing) things.
Re: The Shortest Crashing C Program
#90Who says it will crash? Could run very nicely, printing a list of prime numbers, or write poetry, or anything else that undefined behaviour encompasses.
Maybe the task should have been formulated as the shortest valid C program that invokes undefined behaviour instead. (Or maybe the task isn't very interesting either way.)