Chase Minor
Chase Minor

Reputation: 11

Is there a limit to the types of NSConstantString's allowable in gnustep while loops?

Recently I hit an issue with compiling constant @strings in objective-c.

Below is a reproduction of the issue.

This case is fine.

#import<Foundation/Foundation.h>

int main() {
   BOOL condition = NO;
   while(condition) {
      NSLog(@"12345678");
      return 0;
   }
}

This case is not fine.

#import<Foundation/Foundation.h>

int main() {
   BOOL condition = NO;
   while(condition) {
      NSLog(@"123456789");
   }
}

Error

/tmp/test-1ad248.o:test.m:.objc_init: error: undefined reference to '__start___objc_constant_string'
/tmp/test-1ad248.o:test.m:.objc_init: error: undefined reference to '__stop___objc_constant_string'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Furthermore, this case is fine.

#import<Foundation/Foundation.h>

int main() {
   NSLog(@"123456789");
}

My guess is that this is something to do with storing the string as a bytes in a pointer in a dense fashion. IE 64-bit system has 8 char bytes per pointer. so 1 through 8 is fine but not 1 through 9. However, I do not know how to fix this issue.

It even fails with the following

#import<Foundation/Foundation.h>

int main() {
  BOOL condition = NO;
  NSString *msg = @"123456789";
  while (condition) {
    NSLog(@"%@", msg);
  }
}

System

Upvotes: 1

Views: 47

Answers (0)

Related Questions