Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] C puzzle



>>>>> "DS" == David Santinoli <u235@example.com> writes:

    DS> On Tue, Jul 30, 2002 at 11:29:45AM -0400, Viktor Pavlenko wrote:
    >> 
    >> What about the one which always crashes?
    >> 
    >> The following program contains 25 characters, uses no library
    >> functions and segfaults when run:
    >> 
    >> main(){((void(*)())0)();}

    DS> echo 'main(){main();}' > f.c ; gcc -o f f.c ; ./f ; rm f.c f

    DS> Sooner or later it *should* get out of stack space, shouldn't
    DS> it? ;-)

Okay, yours is shorter, but mine is faster :)

$ echo 'main(){main();}' > f.c ; gcc -o f f.c ; time ./f ; rm f.c f
Segmentation fault

real	0m0.045s
user	0m0.010s
sys	0m0.030s
$ echo 'main(){((void(*)())0)();}' > f.c ; gcc -o f f.c ; time ./f ; rm f.c f
Segmentation fault

real	0m0.002s
user	0m0.000s
sys	0m0.000s

Viktor


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links