Mailing List Archive


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

Re: [tlug] C puzzle



>>>>> "ND" == Norman Diamond <ndiamond@example.com> writes:

    ND> (2)

    ND> Dereferencing a null pointer is clearly incorrect.  An
    ND> implementation is allowed to do things other than crash, it is
    ND> allowed to print 20 minus signs.  One rather famous
    ND> implementation, which makes this posting almost on-topic,
    ND> validly exec'ed rogue when it found a #pragma, and it would be
    ND> equally valid if it exec'ed rogue when it found a program
    ND> dereferencing a null pointer.

In general I agree. But: 0 address is outside of allowed memory range
and SIGSEGV is naturally sent to the program that is trying to use it.
In other words, it's undefined but you can expect segfault from the
compilers you know on the systems you know (who said C is inherently
portable?). Btw, unsigned integer underflow (int*i solution to the
puzzle) is undefined too. As well as ~i solution I believe.

    ND> (3)

    ND> If a crash is desired, the abort function is pretty well
    ND> defined to do it.  The crash doesn't have to resemble other
    ND> kinds of crashes, but it's the closest thing we have to a
    ND> guarantee of getting a crash.

That's a very good point, how could I forget about abort(3) :)

Viktor


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links