Mailing List Archive


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

Re: [tlug] C puzzle



>>>>> "JG" == Josh Glover <jmglov@example.com> writes:

    >> main(){((void(*)())0)();}

    JG> Now *that* is w4j 1337!

I guess so, whatever it is :)

    JG> OK, here is my best guess of how it works:

    JG> main() contains one function call, which is typecast as a void
    JG> pointer.  Therefore, the 0 is actually the function name,
    JG> right? So what happens when you exec it is it tries to exec
    JG> whatever function lies at the memory address 0x0, and that
    JG> causes a segfault.

In general, yes. Some corrections: in order to call a function (apply
`()') I need a function type, so I cast 0 to be a value of a pointer
to function which takes no args and returns nothing, and then call it.

Viktor


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links