Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
muntoo
Posts: 834 Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:
Post
by muntoo » 25 Jun 2011, 20:46
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
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
Post
by HaWe » 25 Jun 2011, 20:53
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:
Post
by muntoo » 25 Jun 2011, 22:01
Stringification
OK, fine, let's try this then:
Nice and simple. Should work. Doesn't.
Ideone runs
this OK, so I'm pretty sure I haven't gone crazy.
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:
Post
by spillerrec » 26 Jun 2011, 07:10
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.
afanofosc
Site Admin
Posts: 1256 Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:
Post
by afanofosc » 26 Jun 2011, 14:09
Yes, I have not implemented support for stringification. It may not be something I ever get around to adding to my preprocessor.
John Hansen
Users browsing this forum: No registered users and 2 guests