[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with NSString
From: |
David Chisnall |
Subject: |
Re: Problem with NSString |
Date: |
Mon, 31 Jan 2011 09:38:06 +0000 |
On 31 Jan 2011, at 00:28, Lars Sonchocky-Helldorf wrote:
>>> And not only that. It is also a good practice of defensive coding, e.g. you
>>> don't run into problems if word2 happens to be Nil.
>>
>> But, sending message to nil is safe and returns zero :-)
>
> Well there it shows I am earning my money coding Java. In that language you
> don't have the comfort of being able to send messages to null without
> consequences :-(
Technically, sending a message to nil returns 0 in the integer-return register.
Sending a message to nil that returns a float or a structure has undefined
behaviour. In GCC on SPARC, for example, sending a structure-returning message
to nil causes an illegal instruction trap and aborts your program[1]. On OS X,
you will get the first field in the structure filled with 0, but the rest are
undefined.
Clang 2.8 includes some really horrible code to work around this, and now
guarantees that every message sent to nil returns 0, irrespective of the return
type (so, a structure return will be filled with zeros). This seemed easier
than making everyone fix their code...
David
[1] This is usually a nice feature of the SPARC ABI, because it stops you from
corrupting your stack in some common cases with C. It's just a bit
inconvenient for ObjC.
-- Sent from my Apple II
- Problem with NSString, Parag Deshpande, 2011/01/30
- Re: Problem with NSString, Stefan Bidi, 2011/01/30
- Re: Problem with NSString, Ivan Vučica, 2011/01/30
- Re: Problem with NSString, David Chisnall, 2011/01/30
- Re: Problem with NSString, Lars Sonchocky-Helldorf, 2011/01/30
- Re: Problem with NSString, Ivan Vučica, 2011/01/30
- Re: Problem with NSString, David Chisnall, 2011/01/30
- Re: Problem with NSString, Ivan Vučica, 2011/01/30
- Re: Problem with NSString, Lars Sonchocky-Helldorf, 2011/01/30
- Re: Problem with NSString,
David Chisnall <=
- Re: Problem with NSString, Ivan Vučica, 2011/01/31
- Re: Problem with NSString, David Chisnall, 2011/01/31
- Re: Problem with NSString, Ivan Vučica, 2011/01/31
- Message not available
- Re: Problem with NSString, Ivan Vučica, 2011/01/31
Re: Problem with NSString, Ivan Vučica, 2011/01/30