Page 1 of 1

[NXC][BUG]OpenFileRead string array bug

Posted: 18 Mar 2011, 08:02
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

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

Posted: 18 Mar 2011, 09:07
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

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

Posted: 18 Mar 2011, 09:13
by timpattinson
Ok, thanks
-Tim
ps. maybe you should include this in the docs somehow

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

Posted: 18 Mar 2011, 21:24
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