NXC: whats wrong with string SLAVE[4]; ?

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

NXC: whats wrong with string SLAVE[4]; ?

Post by HaWe »

Code: Select all

// Name of the Slave NXT.
string SLAVE[4];
SLAVE[0]= "000";  // dummy
SLAVE[1]= "001";
SLAVE[2]= "002";
SLAVE[3]= "003";
I get the compiler error
# Error: ';' expected
File "c:\Temp\temp.nxc" ; line 22
# SLAVE[
#----------------------------------------------------------
# Error: ';' expected
File "c:\Temp\temp.nxc" ; line 23
# SLAVE[
#----------------------------------------------------------
# Error: ';' expected
File "c:\Temp\temp.nxc" ; line 24
# SLAVE[
#----------------------------------------------------------
# Error: ';' expected
File "c:\Temp\temp.nxc" ; line 25
# SLAVE[
the same it is when I use

Code: Select all

int TONE[5];
TONE[0]=TONE_C4;
TONE[1]=TONE_E4;
TONE[2]=TONE_G4;
TONE[3]=TONE_C5;
TONE[4]=TONE_E5;
mcsummation
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

Re: NXC: whats wrong with string SLAVE[4]; ?

Post by mcsummation »

Is it within the scope of a task, sub, etc.? Or is this up in the declarations part of the code (up top)? I got it to compile by putting in the task main() area.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: whats wrong with string SLAVE[4]; ?

Post by HaWe »

they all are global variables at the very top of the code
mcsummation
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

Re: NXC: whats wrong with string SLAVE[4]; ?

Post by mcsummation »

But, you cannot put assignment statements outside the scope of a task, sub, function, etc. SLAVE[0]= "000"; is an assignment statement.

You either need to use

Code: Select all

    // Name of the Slave NXT.
    string SLAVE[4] = {"000","001","002","003"};
or move the assignment statements into an initialization routine.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: whats wrong with string SLAVE[4]; ?

Post by HaWe »

uuuh, yes -
the error report was misleading complaining about ";"
:(
mcsummation
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

Re: NXC: whats wrong with string SLAVE[4]; ?

Post by mcsummation »

Almost always, the ";" complaint is on the line below the actual error. The source scanner has scanned the first and second lines before it finds a "statement end" delimiter, which is usually a ";" or "}", then it says, "Man this statement makes no sense at all. Give the programmer an error and let him figure out what's wrong".

Oh, BTW, I see lots of "missing ;" errors. I let the compiler proofread my code :D
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests