[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.4 Constant string objects

GNU Objective-C provides constant string objects that are generated directly by the compiler. You declare a constant string object by prefixing a C constant string with the character `@':

  id myString = @"this is a constant string object";

The constant string objects are usually instances of the NXConstantString class which is provided by the GNU Objective-C runtime. To get the definition of this class you must include the `objc/NXConstStr.h' header file.

User defined libraries may want to implement their own constant string class. To be able to support them, the GNU Objective-C compiler provides a new command line options `-fconstant-string-class=class-name'. The provided class should adhere to a strict structure, the same as NXConstantString's structure:

@interface NXConstantString : Object
  char *c_string;
  unsigned int len;

User class libraries may choose to inherit the customized constant string class from a different class than Object. There is no requirement in the methods the constant string class has to implement.

When a file is compiled with the `-fconstant-string-class' option, all the constant string objects will be instances of the class specified as argument to this option. It is possible to have multiple compilation units referring to different constant string classes, neither the compiler nor the linker impose any restrictions in doing this.

This document was generated by Charlie & on June, 17 2001 using texi2html