Jump to content

Preprocessor # (string literal) behavior


photo

Recommended Posts

Hello !

 

When using defines to make methods and methods names, it appears that if theses defines are followed by comments, it could lead to error in the script.

 

Look at the code below :

#define S(arg)  	#arg
#define CALLBACK_METHOD   callback// Blah
#define CALLBACK_METHOD_NAME S(CALLBACK_METHOD)

void CALLBACK_METHOD()
{
  log.message("Called\n") ;
}

int init()
{
  call(CALLBACK_METHOD_NAME) ;
  return 1 ;
}

 

If you paste it in an empty world and load it it will work.

 

Now, look at the code below that is the same but with a space between the define and its comment :

#define S(arg)  	#arg
#define CALLBACK_METHOD   callback // Blah
#define CALLBACK_METHOD_NAME S(CALLBACK_METHOD)

void CALLBACK_METHOD()
{
  log.message("Called\n") ;
}

int init()
{
  call(CALLBACK_METHOD_NAME) ;
  return 1 ;
}

 

Load the world again -> CALLBACK_METHOD could not be found.

 

It seems that the # string literal directive leads to some errors because if you directly type the method name in the call instruction it works again.

 

Hope its clear B)

Link to comment
  • 2 weeks later...

For now please do not use comments with defines. Added to the bug list, but really can't promise our devs will look into this issue any time soon, since it's not critical :( Too focused on other issues and suggestions.

Link to comment
×
×
  • Create New...