preprocessor bug: @ + MACRO does not work in gcc-3.0

Nicola Pero n.pero@mi.flashnet.it
Mon Mar 5 09:03:00 GMT 2001


To test objc in gcc-3.0, I'm trying to compile (part of - the ones without
protocols) the gnustep base library sources - and I got into the following
problem - 

we had the following code in NSBundle.m:

static NSString	*gnustep_target_dir = 
#ifdef GNUSTEP_TARGET_DIR
  @GNUSTEP_TARGET_DIR;
#else
  nil;
#endif

then, we compile with the compiler flag -DGNUSTEP_TARGET_DIR=\"ix86/linux-gnu\"

With gcc-2.95.2, the preprocessor replaces the macro, generating 

static NSString *gnustep_target_dir = @"ix86/linux-gnu";

which is then compiled by the Objective-C compiler into Objective-C - at
that stage, @"ix86/linux-gnu" is turned into an Objective-C constant
string and all works.

With gcc-3.0, I get the following error - 

NSBundle.m:88: invalid identifier `@GNUSTEP_TARGET_DIR'
NSBundle.m:88: `@GNUSTEP_TARGET_DIR' undeclared here (not in a function)

and compilation aborts.

--

Here is a new test for the objective-c testsuite, encapsulating the
problem.  The test compiles and runs on 2.95.2 and fails compilation on
3.x. 

Please commit the test and I think whoever works on the preprocessor stuff
should fix it.



/* Contributed by Nicola Pero  Mon Mar  5 20:09:25 CET 2001 */

#include <string.h>
#include <objc/NXConstStr.h>

#define STRING "this is a string"

int main (int argc, void **args)
{
  const char *stringA = "this is a string";
  const char *stringB = [@STRING cString];
  
  return strcmp (stringA, stringB);
}






More information about the Gcc-bugs mailing list