pointerstinyosnesc

Pointer error when compiling nesc


I have the following method/event in nesc. I am getting an error

event message_t* Receive.receive(message_t* bufPtr,
void* payload, uint8_t len) {
dbg("RadioCountToLedsC", "Received packet of length %hhu.\n", len);
radio_count_msg_t* adammsg = (radio_count_msg_t*) payload;
val =adammsg -> counter;
dbg("RadioCountToLedsC", "The current summation is: %d \n", val);
return bufPtr;
}

on the 4th line of this block of code. The error specifically is: "Syntax error before '*'. It then says adammsg is undeclared in the next line

Can anyone tell me what my error could possibly be? I've been stuck on this for a while and it's been driving me insane. I'm working on the RadioCountsToLeds app that is included in Tinyos. Specifically I am trying to inject packets- send them to nodes- and then do computations on the information stored in the packets.

Thanks!


Solution

  • In C (and nesC as well), all declarations of variables must be at the begin of a function. So:

    event message_t* Receive.receive(message_t* bufPtr,
    void* payload, uint8_t len) {
    radio_count_msg_t* adammsg = (radio_count_msg_t*) payload;
    dbg("RadioCountToLedsC", "Received packet of length %hhu.\n", len);
    val =adammsg -> counter;
    dbg("RadioCountToLedsC", "The current summation is: %d \n", val);
    return bufPtr;
    }