[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Creating a GNUstep desktop on Solaris
From: |
Adam Fedor |
Subject: |
Re: Creating a GNUstep desktop on Solaris |
Date: |
Thu, 6 Jan 2005 10:08:34 -0700 |
On Jan 6, 2005, at 9:35 AM, Andreas Höschler wrote:
Yes it is standard behavior, and ObjC does ignore a message to a nil
object and just returns 'NULL'. The problem is Solaris chokes when
you try to assign a 'NULL' to a structure. Even this should crash
Solaris (if you could actually compile it, which you can't since the
compiler is smart enough for this):
struct foo {int i; int j;};
struct foo bar;
bar = (struct foo)0;
Haven't tried to compile this example on the Solaris yet, however I
would consider the above code to be illegal, whether this works on
some platforms or not. Assign Null to a structure simply makes no
sence. I would expect that the compiler, or if it goes through the
runtime does not know how to handle this.
Perhaps I should be more specific, much as I love to delve into
compiler and language internals :-)
Of course the above code will not compile (I said so, in fact). It's
really just pseudo-code for a similar problem that occurs in
Objective-C due to function pointer indirection. Thus when the compiler
sees:
struct foo {int i; int j;};
@interface Foo(Category)
- (struct foo) structReturn;
@end
int main()
{
struct foo bar = [(Foo *)nil structReturn];
}
(which is perfectly legal code), it converts the method call into
something like (warning: pseudo-like code here):
struct foo bar = objc_msg_send(nil, @selector(structReturn), args);
which in turn performs some magic to make sure the proper type gets
returned for the selector. Most operating systems seem to handle this
correctly even though it's certainly not clear what happens when you
assign nothing (0, NULL, whatever) to a struct.
IMHO this should be fixed in the TextEdit.app and GNUMail.app sources
and coders should make sure to always check a pointer for NULL before
assigning it to a struc, shouldn't they?
Yes.
Re: Creating a GNUstep desktop on Solaris, Riccardo, 2005/01/08
Re: Creating a GNUstep desktop on Solaris, Christian Plessl, 2005/01/05