discuss-gnustep
[Top][All Lists]
Advanced

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

This NSConstantString thing


From: Markus Hitter
Subject: This NSConstantString thing
Date: Tue, 12 Mar 2002 21:59:46 +0100

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?

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.

In an attempt to find some documentation about what makes an constant string, I found only this in Cocoa's NSString docs:

As a convenience, the Objective-C language also supports the @"..." construct to create a string object constant from 7-bit ASCII encoding:

        NSString *temp = @"/tmp/scratch";

Such an object is created at compile time and exists throughout your program's execution. The compiler makes such object constants unique on a per-module basis, and they're never deallocated (though you can retain and release them as you do any other object).

Unicode characters other than ASCII characters are disallowed explicitely.


Shouldn't we remove the unused unichar representation?

Would clean up code and make it more compatible with future gcc's. Currently, it seems like the data is defined twice.

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.
- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]