[NXC][Compiler Error] Stringify

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

[NXC][Compiler Error] Stringify

Post 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
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: [NXC][Compiler Error] Stringify

Post 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);
}
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: [NXC][Compiler Error] Stringify

Post 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.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: [NXC][Compiler Error] Stringify

Post 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.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: [NXC][Compiler Error] Stringify

Post 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests