knowledge-database (beta)

Current group: comp.lang.objective-c

using custom constant string objects

using custom constant string objects  
Jeremy Brewer
From:Jeremy Brewer
Subject:using custom constant string objects
Date:10 Nov 2004 11:54:55 -0800
Hi,

I'm trying to create a small String class of my own in Objective-C,
and I'm having some trouble getting it compiled. Following the advice
of the GNU Objective-C runtime options that I found with Google, I
defined my new string class as:

#import

@interface ConstantString : Object
{
char *c_string ;
unsigned int length ;
}

- (void) free ;
- (int) length ;
- (char) element: (int) i ;
- (char *) cString ;
- (char *) toCString ;
- (void) print ;
- (void) printToFile: (FILE *) fp ;

@end

I tried to use it in a simple test program:

#import
#import "ConstantString.h"

int main(void)
{
int i ;
char *copy ;
ConstantString *hello = @"hello, world!" ;

i = [hello length] ;
copy = [hello toCString] ;

printf("String hello = '%s'\n", [hello cString]) ;
printf("String copy = '%s'\n", copy) ;

[hello print] ;
[hello free] ;

printf("String copy = '%s'\n", copy) ;

return 0 ;
}

Compiling on the command line with Mac OS X 10.3.6, XCode 1.5, with
the following commands gives

cc test_string.m ConstantString.m -o test_string -O3 -lm -lobjc
-fconstant-string-class=ConstantString -Wall

Gives the following error:

test_string.m: In function `main':
test_string.m:12: error: cannot find reference tag for class
`ConstantString'
make: *** [test_string] Error 1

The error is the line

ConstantString *hello = @"hello, world!" ;

I can't find anything related to this error using Google. Any ideas
what's going wrong?

I get the same error if I change the class definition to

@interface ConstantString {
Class isa;
char *c_string;
unsigned int len;
}
@end

I tried using the GNU runtime instead, but that gave me further errors
(I can supply those if needed).

Jeremy Brewer
   

Copyright © 2006 knowledge-database   -   All rights reserved