[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: This NSConstantString thing
From: |
Richard Frith-Macdonald |
Subject: |
Re: This NSConstantString thing |
Date: |
Tue, 12 Mar 2002 21:36:46 +0000 |
On Tuesday, March 12, 2002, at 08:59 PM, Markus Hitter wrote:
Hi,
with my efforts to get GNUstep to work with the Apple-tweaked gcc 3.1,
I came across an issue with constant strings.
As you probably know, constant strings are declared/defined in code,
but are known to the compiler, too. With Apple's gcc, the compiler
explicitely requires a declaration like:
@interface NXConstantString : NSString /* or NSObject */ {
char *cString;
unsigned int len;
...
}
But GNUstep declares:
@interface NXConstantString : NSString {
union {
unichar *u;
unsigned char *c;
} _contents;
unsigned int _count;
}
which isn't compatible. You notice the additional unicode variable?
It's perfectly compatible, there is no additional variable,
what you are looking at (_contents) is a union ... a single variable.
In an experiment I renamed the variable; the whole base library still
compiles fine. Obviously, the unicode representation isn't used
anywhere. Even if it was, the characters would have to be en- btw.
decoded.
Actually the unicode representation is used for the standard unicode
concrete
subclass of the NSString class. The declaration of NXConstantString is
the
same as that of the private subclasses because the ivar layout of the
two *must*
be the same - and declaring them identically (as well as putting
comments in the
source) is the clearest way of showing that.
Shouldn't we remove the unused unichar representation?
No ... because there is no such unused representation.
Would clean up code and make it more compatible with future gcc's.
Currently, it seems like the data is defined twice.
No ... because it's a union ... and it is in no way incompatible with
any gcc - this is 100% standard C
Can't speak for non-Apple gcc's since gcc 3.0.4 doesn't compile on
Darwin and I don't have an other OS available currently.
Any comments?
Markus
P.S.: yesterday, Adam Fedor kindly added the gcc 3.1 compatible version
to GNUstep base sources (Headers/gnustep/base/NSString.h) so you can
have a look at the situation yourself.
I believe that the addition Adam made for you is in error.
I'd have to check to see if it has any effect (ie if the
NXConstantString declaration is
actually used other than to keep the compiler happy) - but if it does,
it will break
NXConstantString objects.