NS-2.27 and Leach

Friday, April 16, 2004

A GOTO statement in wireless-phy.cc!?

Problem:
Wow. I haven't seen these since GWBASIC. A goto statement jumps over declarations in the MIT code.

mac/wireless-phy.cc: In member function `virtual int
WirelessPhy::sendUp(Packet*)':
mac/wireless-phy.cc:483: error: jump to label `DONE'
mac/wireless-phy.cc:387: error: from here
mac/wireless-phy.cc:397: error: crosses initialization of `int code'
mac/wireless-phy.cc:393: error: crosses initialization of `hdr_rca*rca_hdr'
mac/wireless-phy.cc:392: error: crosses initialization of `hdr_cmn*ch'


Fix:
I just moved the declarations up to the top of the function before any goto statements.

int
WirelessPhy::sendUp(Packet *p)
{
/*
* Sanity Check
*/
assert(initialized());

PacketStamp s;
double Pr;
int pkt_recvd = 0;

#ifdef MIT_uAMPS
hdr_cmn *ch = HDR_CMN(p);
hdr_rca *rca_hdr = HDR_RCA(p);
int code = rca_hdr->get_code();
#endif

// if the node is in sleeping mode, drop the packet simply
if (em())
...

0 Comments:

Post a Comment

<< Home