[NXC][BUG]OpenFileRead string array bug

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
timpattinson
Posts: 224
Joined: 30 Oct 2010, 04:10
Location: 127.0.0.1
Contact:

[NXC][BUG]OpenFileRead string array bug

Post by timpattinson »

With the following code, I get a NBC (not NXC) compiler error

Code: Select all

task main()
{
string MyStringArray[] = {"abc.txt","123.txt","lifeuniverse_etc.txt","NXCisgr8.txt"};
NumOut(0,LCD_LINE1,MyStringArray[1]);
int fsize;
byte handle;
OpenFileRead(MyStringArray[2],fsize,handle); // is this a bug??????
CloseFile(handle);

}
The error is

Code: Select all

# Error: Error parsing expression: __main_7qG2_MyStringArray_7qG2_000[2]
File "C:\Documents and Settings\pattinsont\Desktop\NXC\bug.nxc" ; line 7
#   
#----------------------------------------------------------
1 errors during compilation
Line 7 is the line with OpenFileRead, the filename parameter is MyStringArray[2] which should be "123.txt"

How do you get the NBC when it dosen't compile?
Thanks,
Tim
Commit to Lego Mindstorms StackExchange Q&A http://area51.stackexchange.com/proposals/4105
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: [NXC][BUG]OpenFileRead string array bug

Post by afanofosc »

A number of NXC API functions are #define macros that emit asm blocks. These API functions cannot take an NXC expression as a parameter since the expression would be passed by the preprocessor into the NBC asm block and the NBC back end does not know how to evaluate and NXC expression. You need to store the result of the expression in a variable which you then pass into the function.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
timpattinson
Posts: 224
Joined: 30 Oct 2010, 04:10
Location: 127.0.0.1
Contact:

Re: [NXC][BUG]OpenFileRead string array bug

Post by timpattinson »

Ok, thanks
-Tim
ps. maybe you should include this in the docs somehow
Commit to Lego Mindstorms StackExchange Q&A http://area51.stackexchange.com/proposals/4105
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: [NXC][BUG]OpenFileRead string array bug

Post by afanofosc »

The help for OpenFileRead says "The filename parameter must be a constant or a variable." Which is to say "it cannot be an NXC expression".

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest