NXC: strange error msg at inline function

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

NXC: strange error msg at inline function

Post by HaWe »

if I'm using a printf cmd for debugging I get strange error msgs - commenting them out it runs without problems. why?

Code: Select all

#define printf1( _x, _y, _format1, _value1) { \
  string sval1 = FormatNum(_format1, _value1); \
  TextOut(_x, _y, sval1); \
}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
inline void ParseBTResponseMsg(char ID, string str)  // slaveID=0...2
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
    string pstr, rstr, vstr, sp, sn;
    int i, p, n, len, v;

    len=StrLen(str);   //

    for (i=0; i<11; i++)
    {
       sp=SubStr(str,0,1);  p=StrToNum(sp);

       printf1(0,48,"%2d",i); printf1(24,48,"%2d",p);  // <<<<<<<<<< out-commented: nor error !

       p=i;
                                                                              // <<<<<<<<< = line 335
       sn=SubStr(str,1,1);       // dec
       n=StrToNum(sn);

       vstr=SubStr(str, 2, n);   // n= length of value string
       v=StrToNum(vstr);
       SensorRemoteArray[ID][p]=v;

       rstr=SubStr(str, 2+n, len);
       str=rstr;
       len=StrLen(str);
    }
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
task ReceiveSlaveData()    // NOS = Number of Slaves
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
   string _msg;

   while(true)

   {
     if (_NOS_>=1) {
       until(ReceiveRemoteString(INBOX_11, true, _msg) == NO_ERR);
       ParseBTResponseMsg(0, _msg) ;   //                                           <<<<<<<<<   = line 360
       Wait(10);
     }

     if (_NOS_>=2) {
       until(ReceiveRemoteString(INBOX_21, true, _msg) == NO_ERR);
       ParseBTResponseMsg(1, _msg) ;
       Wait(10);
     }

     if (_NOS_==3) {
       until(ReceiveRemoteString(INBOX_31, true, _msg) == NO_ERR);
       ParseBTResponseMsg(2, _msg) ;
       Wait(10);
      }

     Wait(10);

   }
}

# Error: Duplicate variable declaration (__ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData)
File "c:\Temp\temp.nxc" ; line 360
# __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData byte[] {0x00}
#----------------------------------------------------------
# Error: Invalid variable argument: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 335
# mov __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData, __strbufParseBTResponseMsg_inline_ReceiveSlaveData
#----------------------------------------------------------
# Error: Error parsing expression: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 335
#
#----------------------------------------------------------
# Error: Invalid string argument: __constVal0
File "c:\Temp\temp.nxc" ; line 335
# strcat __strbufParseBTResponseMsg_inline_ReceiveSlaveData, __constVal0
#----------------------------------------------------------
# Error: Invalid variable argument: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 336
# mov __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData, __strbufParseBTResponseMsg_inline_ReceiveSlaveData
#----------------------------------------------------------
# Error: Error parsing expression: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 336
#
#----------------------------------------------------------
# Error: Invalid string argument: __constVal0
File "c:\Temp\temp.nxc" ; line 336
# strcat __strbufParseBTResponseMsg_inline_ReceiveSlaveData, __constVal0
#----------------------------------------------------------
# Error: Invalid variable argument: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 335
# mov __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData, __strbufParseBTResponseMsg_inline_ReceiveSlaveData
#----------------------------------------------------------
# Error: Error parsing expression: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 335
#
#----------------------------------------------------------
# Error: Invalid string argument: __constVal0
File "c:\Temp\temp.nxc" ; line 335
# strcat __strbufParseBTResponseMsg_inline_ReceiveSlaveData, __constVal0
#----------------------------------------------------------
# Error: Invalid variable argument: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 336
# mov __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData, __strbufParseBTResponseMsg_inline_ReceiveSlaveData
#----------------------------------------------------------
# Error: Error parsing expression: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 336
#
#----------------------------------------------------------
# Error: Invalid string argument: __constVal0
File "c:\Temp\temp.nxc" ; line 336
# strcat __strbufParseBTResponseMsg_inline_ReceiveSlaveData, __constVal0
#----------------------------------------------------------
# Error: Invalid variable argument: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 335
# mov __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData, __strbufParseBTResponseMsg_inline_ReceiveSlaveData
#----------------------------------------------------------
# Error: Error parsing expression: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 335
#
#----------------------------------------------------------
# Error: Invalid string argument: __constVal0
File "c:\Temp\temp.nxc" ; line 335
# strcat __strbufParseBTResponseMsg_inline_ReceiveSlaveData, __constVal0
#----------------------------------------------------------
# Error: Invalid variable argument: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 336
# mov __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData, __strbufParseBTResponseMsg_inline_ReceiveSlaveData
#----------------------------------------------------------
# Error: Error parsing expression: __ParseBTResponseMsg_7qG2_sval1_7qG2_003_inline_ReceiveSlaveData_inline_ReceiveSlaveData
File "c:\Temp\temp.nxc" ; line 336
#
#----------------------------------------------------------
# Error: Invalid string argument: __constVal0
File "c:\Temp\temp.nxc" ; line 336
# strcat __strbufParseBTResponseMsg_inline_ReceiveSlaveData, __constVal0
#----------------------------------------------------------
19 errors during compilation
Last edited by HaWe on 23 Feb 2012, 23:05, edited 1 time in total.
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC: strange error msg at inline function

Post by spillerrec »

Define sval1 globally instead of inside the macro function and it compiles fine. I'm not quite sure why, but I think I remember something about there being issues with using the same variable names in separate scopes which have the same level.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: strange error msg at inline function

Post by HaWe »

yes, now it really works!
thanks a lot!
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: strange error msg at inline function

Post by afanofosc »

My recollection is that if the variables are all the same type then there is not a problem with them having the same name at the same scope level. But if you try to use a variable with the same name as a variable with a different type at the same scope level the compiler will get upset.

It looks, though, like this is a new bug that I have not seen before (or, at least, do not recall having seen before) where if you use a variable with the same name at the same scope in an inline function that the compiler gets upset. It works fine if the function is not inline. It also works fine if you wrap each printf in a different number of braces so that they have different scopes.

I'll see if I can figure out a fix for this defect.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: strange error msg at inline function

Post by HaWe »

Image
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests