Page 1 of 1

NXC: strange error msg at inline function

Posted: 21 Feb 2012, 19:03
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

Re: NXC: strange error msg at inline function

Posted: 21 Feb 2012, 19:58
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.

Re: NXC: strange error msg at inline function

Posted: 21 Feb 2012, 20:08
by HaWe
yes, now it really works!
thanks a lot!

Re: NXC: strange error msg at inline function

Posted: 21 Feb 2012, 23:42
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

Re: NXC: strange error msg at inline function

Posted: 22 Feb 2012, 08:07
by HaWe
Image