[Tinyos-help] a strange error

Murray, Ben Ben.Murray at thalesgroup.com
Tue Mar 11 06:27:31 PDT 2008


That is a pretty common, and standard C error.
You cannot perform an operation prior to declaring a variable (...or: you
cannot declare a variable /after/ an operation has been performed)

In this case the function start is the  open-brace of the else command:
begin-brace	> 	  else {
operation	> 	    Counter++; 
declaration	> 	    radio_test_msg_t* rcm =
(radio_test_msg_t*)call...
produces an error as it is "not allowed".

If you want it there you either declare rcm at the start of the .fired()
event or you put the counter++ operation /after/ the rcm declaration:
begin-brace	> 	  else {
declaration	> 	    radio_test_msg_t* rcm =
(radio_test_msg_t*)call...
operation	> 	    Counter++; 
should work fine.

Cheers
-Ben


> -----Original Message-----
> From: tinyos-help-bounces at millennium.berkeley.edu
> [mailto:tinyos-help-bounces at millennium.berkeley.edu]On Behalf 
> Of weiping
> SONG
> Sent: 11 March 2008 12:33
> To: tinyos-help at millennium.berkeley.edu
> Subject: [Tinyos-help] a strange error 
> 
> 
> Hi all,
> 
> I faced a strange error  this morning as following:
> I could not compile my TestRadioAppC.nc if I put "Counter++;" before 
> radio_test_mag_t in TestRadioC.nc...
> 
> ---------------------------------------------------------------------
> event void TimerRadio.fired() {
> 	 // Counter++;
> 	  if (locked) {
> 	    return;
> 	  }
> 	  else {
> 	    Counter++;
> 	    radio_test_msg_t* rcm = (radio_test_msg_t*)call 
> Packet.getPayload(&packet, NULL);
> 	    if (call Packet.maxPayloadLength() < 
> sizeof(radio_test_msg_t)) {
> 	      return;
> 	    }
> 
> 	    rcm->voltage = InVoltage;
> 	    rcm->count = Counter;
> 	    rcm->temp = 0;
> 	    if (call AMSend.send(AM_BROADCAST_ADDR, &packet, 
> sizeof(radio_test_msg_t)) == SUCCESS) {
> 		 locked = TRUE;
> 	    }
> 	  }
> 	}
> --------------------------------------------------------------
> --------------------------------------------
> [realtime at m1-02 TestRadio]$ make telosb
> mkdir -p build/telosb
>     compiling TestRadioAppC to a telosb binary
> ncc -o build/telosb/main.exe -Os -O -mdisable-hwmul -Wall 
> -Wshadow -DDEF_TOS_AM_GROUP=0x7d -Wnesc-all -target=telosb 
> -fnesc-cfile=build/telosb/app.c -board= 
> -DIDENT_PROGRAM_NAME=\"TestRadioAppC\" 
> -DIDENT_USER_ID=\"realtime\" 
> -DIDENT_HOSTNAME=\"m1-02.ucc.ie\" 
> -DIDENT_USER_HASH=0x69427c28L -DIDENT_UNIX_TIME=0x47d67976L 
> -DIDENT_UID_HASH=0xc8fd72abL  TestRadioAppC.nc -lm
> In file included from TestRadioAppC.nc:13:
> In component `TestRadioC':
> TestRadioC.nc: In function `TimerRadio.fired':
> TestRadioC.nc:47: syntax error before `*'
> TestRadioC.nc:52: `rcm' undeclared (first use in this function)
> TestRadioC.nc:52: (Each undeclared identifier is reported only once
> TestRadioC.nc:52: for each function it appears in.)
> make: *** [exe0] Error 1
> [realtime at m1-02 TestRadio]$
> 
> --------------------------------------------------------------
> --------------------------------------------------------------------
> 
> But it worked well if I put "Counter++;" in the first line of 
> the event.
> 
> I do not understand why, can some one help me?
> 
> Regards,
> 
> Weiping Song
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help at millennium.berkeley.edu
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/t
inyos-help

*******************************************************************************
Please consider the environment before printing this email.
*******************************************************************************
This email and any files transmitted with it are intended solely for the use of
the individual or entity to whom they are addressed and may not be divulged to
any third party without the express permission of the originator.  Any views
expressed in this message are those of the individual sender, except where the
sender specifically states them to be the views of Thales Research & Technology
(UK) Limited.
*******************************************************************************



More information about the Tinyos-help mailing list