Page 1 of 1

[NXC][Compiler Error] Stringify

Posted: 25 Jun 2011, 20:46
by muntoo
This:

Code: Select all

#define STR(x) #x

task main()
{
	TextOut(0, 0, STR(Hello World), 0);
	Wait(2000);
}
Gives me:

Code: Select all

# Error: String return value expected
File "C:\Documents and Settings\All Users\Documents\MatData10\NXT-Programs\NXT-BRICXCC\NXC\MemoryManager\Stringify test.nxc" ; line 7
#    Wait(
#----------------------------------------------------------
# Error: ')' expected
File "C:\Documents and Settings\All Users\Documents\MatData10\NXT-Programs\NXT-BRICXCC\NXC\MemoryManager\Stringify test.nxc" ; line 7
#    Wait(
#----------------------------------------------------------
# Error: ';' expected
File "C:\Documents and Settings\All Users\Documents\MatData10\NXT-Programs\NXT-BRICXCC\NXC\MemoryManager\Stringify test.nxc" ; line 7
#    Wait(2

Re: [NXC][Compiler Error] Stringify

Posted: 25 Jun 2011, 20:53
by HaWe
IMHO #x is no string, but "#x" is...

Code: Select all

#define STR(x) "#x"

task main()
{
   TextOut(0, 0, STR(Hello World), 0); // STR(Hello World): string expected
   Wait(2000);
}

Code: Select all

#define STR(x) "#"+x

task main()
{
   TextOut(0, 0, STR("Hello World"), 0); // STR(Hello World): string expected
   Wait(2000);
}

Re: [NXC][Compiler Error] Stringify

Posted: 25 Jun 2011, 22:01
by muntoo
Stringification

OK, fine, let's try this then:

Code: Select all

TextOut(0, 0, STR(abc) , 0);
Nice and simple. Should work. Doesn't.

Ideone runs this OK, so I'm pretty sure I haven't gone crazy.

Re: [NXC][Compiler Error] Stringify

Posted: 26 Jun 2011, 07:10
by spillerrec
You have not gone crazy, I'm just pretty sure it haven't been implemented. NXC Programmer's Guide lists which preprocessor directives are supported and "#" is not included there.

Re: [NXC][Compiler Error] Stringify

Posted: 26 Jun 2011, 14:09
by afanofosc
Yes, I have not implemented support for stringification. It may not be something I ever get around to adding to my preprocessor.

John Hansen