# HG changeset patch # User Andrey Mazo # Date 1328886132 -14400 # Node ID aef733235832440bbe1c70fd9c7ec306b7574749 # Parent a982d8c7aa32f273fd0110cd84509da35ac4f56c Bug 1170: Formulate best practices for dealing with unused debug variables. diff --git a/examples/energy/energy-model-example.cc b/examples/energy/energy-model-example.cc --- a/examples/energy/energy-model-example.cc +++ b/examples/energy/energy-model-example.cc @@ -35,6 +35,20 @@ using namespace ns3; +std::string +PrintReceivedPacket (Address& from) +{ + InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (from); + + std::ostringstream oss; + oss << "--\nReceived one packet! Socket: " << iaddr.GetIpv4 () + << " port: " << iaddr.GetPort () + << " at time = " << Simulator::Now ().GetSeconds () + << "\n--"; + + return oss.str (); +} + /** * \param socket Pointer to socket. * @@ -49,13 +63,7 @@ { if (packet->GetSize () > 0) { - InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (from); - NS_LOG_UNCOND ("--\nReceived one packet! Socket: "<< iaddr.GetIpv4 () - << " port: " << iaddr.GetPort () << " at time = " << - Simulator::Now ().GetSeconds () << "\n--"); - //cast iaddr to void, to suppress 'iaddr' set but not used compiler warning - //in optimized builds - (void) iaddr; + NS_LOG_UNCOND (PrintReceivedPacket (from)); } } } diff --git a/examples/routing/manet-routing-compare.cc b/examples/routing/manet-routing-compare.cc --- a/examples/routing/manet-routing-compare.cc +++ b/examples/routing/manet-routing-compare.cc @@ -117,6 +117,28 @@ { } +std::string +PrintReceivedPacket (Ptr socket, Ptr packet) +{ + SocketAddressTag tag; + bool found; + found = packet->PeekPacketTag (tag); + std::ostringstream oss; + + oss << Simulator::Now ().GetSeconds () << " " << socket->GetNode ()->GetId (); + + if (found) + { + InetSocketAddress addr = InetSocketAddress::ConvertFrom (tag.GetAddress ()); + oss << " received one packet from " << addr.GetIpv4 (); + } + else + { + oss << " received one packet!"; + } + return oss.str (); +} + void RoutingExperiment::ReceivePacket (Ptr socket) { @@ -125,23 +147,7 @@ { bytesTotal += packet->GetSize (); packetsReceived += 1; - SocketAddressTag tag; - bool found; - found = packet->PeekPacketTag (tag); - if (found) - { - InetSocketAddress addr = InetSocketAddress::ConvertFrom (tag.GetAddress ()); - NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << " " << socket->GetNode ()->GetId () - << " received one packet from " << addr.GetIpv4 ()); - //cast addr to void, to suppress 'addr' set but not used - //compiler warning in optimized builds - (void) addr; - } - else - { - NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << " " << socket->GetNode ()->GetId () - << " received one packet!"); - } + NS_LOG_UNCOND (PrintReceivedPacket (socket, packet)); } } diff --git a/examples/stats/wifi-example-apps.h b/examples/stats/wifi-example-apps.h --- a/examples/stats/wifi-example-apps.h +++ b/examples/stats/wifi-example-apps.h @@ -25,8 +25,6 @@ * */ -// #define NS3_LOG_ENABLE // Now defined by Makefile - #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/application.h" diff --git a/examples/stats/wifi-example-sim.cc b/examples/stats/wifi-example-sim.cc --- a/examples/stats/wifi-example-sim.cc +++ b/examples/stats/wifi-example-sim.cc @@ -30,8 +30,6 @@ * */ -// #define NS3_LOG_ENABLE // Now defined by Makefile - #include #include diff --git a/examples/wireless/multirate.cc b/examples/wireless/multirate.cc --- a/examples/wireless/multirate.cc +++ b/examples/wireless/multirate.cc @@ -89,7 +89,6 @@ private: - Vector GetPosition (Ptr node); Ptr SetupPacketReceive (Ptr node); NodeContainer GenerateNeighbors (NodeContainer c, uint32_t senderId); @@ -181,13 +180,6 @@ Simulator::Schedule (Seconds (0.1), &Experiment::CheckThroughput, this); } -Vector -Experiment::GetPosition (Ptr node) -{ - Ptr mobility = node->GetObject (); - return mobility->GetPosition (); -} - /** * * Take the grid map, divide it into 4 quadrants @@ -309,10 +301,16 @@ } } -void -Experiment::ApplicationSetup (Ptr client, Ptr server, double start, double stop) +Vector +GetPosition (Ptr node) { + Ptr mobility = node->GetObject (); + return mobility->GetPosition (); +} +std::string +PrintPosition (Ptr client, Ptr server) +{ Vector serverPos = GetPosition (server); Vector clientPos = GetPosition (client); @@ -325,20 +323,27 @@ Ipv4Address ipv4AddrServer = iaddrServer.GetLocal (); Ipv4Address ipv4AddrClient = iaddrClient.GetLocal (); - NS_LOG_DEBUG ("Set up Server Device " << (server->GetDevice (0))->GetAddress () - << " with ip " << ipv4AddrServer - << " position (" << serverPos.x << "," << serverPos.y << "," << serverPos.z << ")"); + std::ostringstream oss; + oss << "Set up Server Device " << (server->GetDevice (0))->GetAddress () + << " with ip " << ipv4AddrServer + << " position (" << serverPos.x << "," << serverPos.y << "," << serverPos.z << ")"; - NS_LOG_DEBUG ("Set up Client Device " << (client->GetDevice (0))->GetAddress () - << " with ip " << ipv4AddrClient - << " position (" << clientPos.x << "," << clientPos.y << "," << clientPos.z << ")" - << "\n"); + oss << "Set up Client Device " << (client->GetDevice (0))->GetAddress () + << " with ip " << ipv4AddrClient + << " position (" << clientPos.x << "," << clientPos.y << "," << clientPos.z << ")" + << "\n"; + return oss.str (); +} - //cast serverPos,clientPos,iaddrClient to void, to suppress variable set but not - //used compiler warning in optimized builds - (void) serverPos; - (void) clientPos; - (void) ipv4AddrClient; +void +Experiment::ApplicationSetup (Ptr client, Ptr server, double start, double stop) +{ + Ptr ipv4Server = server->GetObject (); + + Ipv4InterfaceAddress iaddrServer = ipv4Server->GetAddress (1,0); + Ipv4Address ipv4AddrServer = iaddrServer.GetLocal (); + + NS_LOG_DEBUG (PrintPosition (client, server)); // Equipping the source node with OnOff Application used for sending OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address ("10.0.0.1"), port))); diff --git a/examples/wireless/wifi-simple-interference.cc b/examples/wireless/wifi-simple-interference.cc --- a/examples/wireless/wifi-simple-interference.cc +++ b/examples/wireless/wifi-simple-interference.cc @@ -96,15 +96,21 @@ using namespace ns3; -void ReceivePacket (Ptr socket) +std::string PrintReceivedPacket (Ptr socket) { Address addr; socket->GetSockName (addr); InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (addr); - NS_LOG_UNCOND ("Received one packet! Socket: " << iaddr.GetIpv4 () << " port: " << iaddr.GetPort ()); - //cast iaddr to void, to suppress iaddr set but not used compiler warning - //in optimized builds - (void) iaddr; + + std::ostringstream oss; + oss << "Received one packet! Socket: " << iaddr.GetIpv4 () << " port: " << iaddr.GetPort (); + + return oss.str (); +} + +void ReceivePacket (Ptr socket) +{ + NS_LOG_UNCOND (PrintReceivedPacket (socket)); } static void GenerateTraffic (Ptr socket, uint32_t pktSize, diff --git a/src/applications/model/packet-sink.cc b/src/applications/model/packet-sink.cc --- a/src/applications/model/packet-sink.cc +++ b/src/applications/model/packet-sink.cc @@ -151,6 +151,17 @@ } } +std::string PrintStats (Address& from, uint32_t packetSize, uint32_t totalRxSize) +{ + std::ostringstream oss; + InetSocketAddress address = InetSocketAddress::ConvertFrom (from); + oss << "Received " << packetSize << " bytes from " + << address.GetIpv4 () << " [" << address << "]" + << " total Rx " << totalRxSize; + + return oss.str (); +} + void PacketSink::HandleRead (Ptr socket) { NS_LOG_FUNCTION (this << socket); @@ -165,13 +176,7 @@ if (InetSocketAddress::IsMatchingType (from)) { m_totalRx += packet->GetSize (); - InetSocketAddress address = InetSocketAddress::ConvertFrom (from); - NS_LOG_INFO ("Received " << packet->GetSize () << " bytes from " << - address.GetIpv4 () << " [" << address << "]" - << " total Rx " << m_totalRx); - //cast address to void , to suppress 'address' set but not used - //compiler warning in optimized builds - (void) address; + NS_LOG_INFO (PrintStats (from, packet->GetSize (), m_totalRx)); } m_rxTrace (packet, from); } diff --git a/src/applications/model/v4ping.cc b/src/applications/model/v4ping.cc --- a/src/applications/model/v4ping.cc +++ b/src/applications/model/v4ping.cc @@ -243,9 +243,6 @@ InetSocketAddress dst = InetSocketAddress (m_remote, 0); status = m_socket->Connect (dst); NS_ASSERT (status != -1); - //cast status to void, to suppress 'status' set but not used compiler warning - //in optimized builds - (void) status; Send (); } diff --git a/src/click/helper/click-internet-stack-helper.cc b/src/click/helper/click-internet-stack-helper.cc --- a/src/click/helper/click-internet-stack-helper.cc +++ b/src/click/helper/click-internet-stack-helper.cc @@ -297,7 +297,6 @@ result = ipv4L3Protocol->TraceConnectWithoutContext ("Rx", MakeCallback (&Ipv4L3ProtocolRxTxSink)); NS_ASSERT_MSG (result == true, "ClickInternetStackHelper::EnablePcapIpv4Internal(): " "Unable to connect ipv4L3Protocol \"Rx\""); - (void) result; //cast to void to suppress variable set but not used compiler warning in optimized builds } g_interfaceFileMapIpv4[std::make_pair (ipv4, interface)] = file; @@ -450,9 +449,9 @@ // be aggregated to the same node. // Ptr ipv4L3Protocol = ipv4->GetObject (); - bool __attribute__ ((unused)) result = ipv4L3Protocol->TraceConnectWithoutContext ("Drop", - MakeBoundCallback (&Ipv4L3ProtocolDropSinkWithoutContext, - theStream)); + bool result = ipv4L3Protocol->TraceConnectWithoutContext ("Drop", + MakeBoundCallback (&Ipv4L3ProtocolDropSinkWithoutContext, + theStream)); NS_ASSERT_MSG (result == true, "ClickInternetStackHelper::EanableAsciiIpv4Internal(): " "Unable to connect ipv4L3Protocol \"Drop\""); } diff --git a/src/click/test/ipv4-click-routing-test.cc b/src/click/test/ipv4-click-routing-test.cc --- a/src/click/test/ipv4-click-routing-test.cc +++ b/src/click/test/ipv4-click-routing-test.cc @@ -97,9 +97,6 @@ ret = simclick_sim_command (click->m_simNode, SIMCLICK_IFID_FROM_NAME, "eth1"); NS_TEST_EXPECT_MSG_EQ (ret, -1, "No eth1 on node"); - - // Cast ret to void to work around set-but-unused warnings from compilers - (void) ret; } class ClickIpMacAddressFromNameTest : public TestCase @@ -152,9 +149,6 @@ NS_TEST_EXPECT_MSG_EQ (strcmp (buf, "00:00:00:00:00:00"), 0, "tun0 has IP 127.0.0.1"); delete [] buf; - - // Cast ret to void to work around set-but-unused warnings from compilers - (void) ret; } class ClickTrivialTest : public TestCase @@ -197,9 +191,6 @@ NS_TEST_EXPECT_MSG_EQ (ret, 0, "eth1 does not exist, so return 0"); delete [] buf; - - // Cast ret to void to work around set-but-unused warnings from compilers - (void) ret; } class ClickIfidFromNameTestSuite : public TestSuite diff --git a/src/core/examples/main-callback.cc b/src/core/examples/main-callback.cc --- a/src/core/examples/main-callback.cc +++ b/src/core/examples/main-callback.cc @@ -34,9 +34,8 @@ // invoke cbOne function through callback instance double retOne; retOne = one (10.0, 20.0); - // cast retOne to void, to suppress variable ‘retOne’ set but - // not used compiler warning - (void) retOne; + // callback returned expected value + NS_ASSERT (retOne == 10.0); // return type: int // first arg type: double @@ -49,9 +48,9 @@ // invoke MyCb::cbTwo through callback instance int retTwo; retTwo = two (10.0); - // cast retTwo to void, to suppress variable ‘retTwo’ set but - // not used compiler warning - (void) retTwo; + // callback returned expected value + NS_ASSERT (retTwo == -5); + two = MakeNullCallback (); // invoking a null callback is just like // invoking a null function pointer: diff --git a/src/core/model/assert.h b/src/core/model/assert.h --- a/src/core/model/assert.h +++ b/src/core/model/assert.h @@ -97,8 +97,19 @@ #else /* NS3_ASSERT_ENABLE */ -#define NS_ASSERT(cond) -#define NS_ASSERT_MSG(cond,msg) +#define NS_ASSERT(condition) \ + do \ + { \ + (void)sizeof (condition); \ + } \ + while (false) + +#define NS_ASSERT_MSG(condition, message) \ + do \ + { \ + (void)sizeof (condition); \ + } \ + while (false) #endif /* NS3_ASSERT_ENABLE */ diff --git a/src/core/model/unused.h b/src/core/model/unused.h new file mode 100644 --- /dev/null +++ b/src/core/model/unused.h @@ -0,0 +1,8 @@ +#ifndef UNUSED_H +#define UNUSED_H + +#ifndef NS_UNUSED +# define NS_UNUSED(x) ((void)(x)) +#endif + +#endif /* UNUSED_H */ diff --git a/src/core/wscript b/src/core/wscript --- a/src/core/wscript +++ b/src/core/wscript @@ -240,7 +240,8 @@ 'model/vector.h', 'model/default-deleter.h', 'model/fatal-impl.h', - 'model/system-path.h' + 'model/system-path.h', + 'model/unused.h', ] if sys.platform == 'win32': diff --git a/src/internet/helper/internet-stack-helper.cc b/src/internet/helper/internet-stack-helper.cc --- a/src/internet/helper/internet-stack-helper.cc +++ b/src/internet/helper/internet-stack-helper.cc @@ -492,9 +492,6 @@ result = ipv4L3Protocol->TraceConnectWithoutContext ("Rx", MakeCallback (&Ipv4L3ProtocolRxTxSink)); NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv4Internal(): " "Unable to connect ipv4L3Protocol \"Rx\""); - // cast result to void, to suppress ‘result’ set but not used compiler-warning - // for optimized builds - (void) result; } g_interfaceFileMapIpv4[std::make_pair (ipv4, interface)] = file; @@ -587,9 +584,6 @@ result = ipv6L3Protocol->TraceConnectWithoutContext ("Rx", MakeCallback (&Ipv6L3ProtocolRxTxSink)); NS_ASSERT_MSG (result == true, "InternetStackHelper::EnablePcapIpv6Internal(): " "Unable to connect ipv6L3Protocol \"Rx\""); - // cast found to void, to suppress ‘result’ set but not used compiler-warning - // for optimized builds - (void) result; } g_interfaceFileMapIpv6[std::make_pair (ipv6, interface)] = file; @@ -822,8 +816,8 @@ // be aggregated to the same node. // Ptr ipv4L3Protocol = ipv4->GetObject (); - bool __attribute__ ((unused)) result = ipv4L3Protocol->TraceConnectWithoutContext ("Drop", - MakeBoundCallback (&Ipv4L3ProtocolDropSinkWithoutContext, theStream)); + bool result = ipv4L3Protocol->TraceConnectWithoutContext ("Drop", + MakeBoundCallback (&Ipv4L3ProtocolDropSinkWithoutContext, theStream)); NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv4Internal(): " "Unable to connect ipv4L3Protocol \"Drop\""); result = ipv4L3Protocol->TraceConnectWithoutContext ("Tx", @@ -1103,8 +1097,8 @@ // be aggregated to the same node. // Ptr ipv6L3Protocol = ipv6->GetObject (); - bool __attribute__ ((unused)) result = ipv6L3Protocol->TraceConnectWithoutContext ("Drop", - MakeBoundCallback (&Ipv6L3ProtocolDropSinkWithoutContext, theStream)); + bool result = ipv6L3Protocol->TraceConnectWithoutContext ("Drop", + MakeBoundCallback (&Ipv6L3ProtocolDropSinkWithoutContext, theStream)); NS_ASSERT_MSG (result == true, "InternetStackHelper::EnableAsciiIpv6Internal(): " "Unable to connect ipv6L3Protocol \"Drop\""); result = ipv6L3Protocol->TraceConnectWithoutContext ("Tx", diff --git a/src/internet/model/ipv6-l3-protocol.cc b/src/internet/model/ipv6-l3-protocol.cc --- a/src/internet/model/ipv6-l3-protocol.cc +++ b/src/internet/model/ipv6-l3-protocol.cc @@ -969,9 +969,7 @@ if (ipv6Extension) { uint8_t nextHeaderStep = 0; -#ifdef NS3_ASSERT_ENABLE uint8_t curHeader = nextHeader; -#endif nextHeaderStep = ipv6Extension->Process (p, nextHeaderPosition, ip, dst, &nextHeader, isDropped); nextHeaderPosition += nextHeaderStep; diff --git a/src/internet/model/nsc-tcp-socket-impl.cc b/src/internet/model/nsc-tcp-socket-impl.cc --- a/src/internet/model/nsc-tcp-socket-impl.cc +++ b/src/internet/model/nsc-tcp-socket-impl.cc @@ -449,9 +449,6 @@ bool found; found = packet->PeekPacketTag (tag); NS_ASSERT (found); - // cast found to void, to suppress 'found' set but not used - // compiler warning in optimized builds - (void) found; fromAddress = tag.GetAddress (); } return packet; diff --git a/src/internet/model/udp-socket-impl.cc b/src/internet/model/udp-socket-impl.cc --- a/src/internet/model/udp-socket-impl.cc +++ b/src/internet/model/udp-socket-impl.cc @@ -547,9 +547,6 @@ bool found; found = packet->PeekPacketTag (tag); NS_ASSERT (found); - //cast found to void, to suppress 'found' set but not used,compiler warning - //in optimized builds - (void) found; fromAddress = tag.GetAddress (); } return packet; diff --git a/src/internet/test/ipv4-fragmentation-test.cc b/src/internet/test/ipv4-fragmentation-test.cc --- a/src/internet/test/ipv4-fragmentation-test.cc +++ b/src/internet/test/ipv4-fragmentation-test.cc @@ -20,7 +20,6 @@ /** * This is the test code for ipv4-l3protocol.cc (only the fragmentation and reassembly part). */ -#define NS3_LOG_ENABLE 1 #include "ns3/test.h" #include "ns3/config.h" diff --git a/src/internet/test/ipv4-header-test.cc b/src/internet/test/ipv4-header-test.cc --- a/src/internet/test/ipv4-header-test.cc +++ b/src/internet/test/ipv4-header-test.cc @@ -105,9 +105,6 @@ NS_ASSERT (m_receivedPacket->GetSize () == 2); m_receivedPacket = socket->Recv (std::numeric_limits::max (), 0); NS_ASSERT (availableData == m_receivedPacket->GetSize ()); - //cast availableData to void, to suppress 'availableData' set but not used - //compiler warning - (void) availableData; m_receivedPacket->PeekHeader (m_receivedHeader); } diff --git a/src/internet/test/ipv4-raw-test.cc b/src/internet/test/ipv4-raw-test.cc --- a/src/internet/test/ipv4-raw-test.cc +++ b/src/internet/test/ipv4-raw-test.cc @@ -114,9 +114,6 @@ NS_ASSERT (m_receivedPacket->GetSize () == 2); m_receivedPacket = socket->Recv (std::numeric_limits::max (), 0); NS_ASSERT (availableData == m_receivedPacket->GetSize ()); - //cast availableData to void, to suppress 'availableData' set but not used - //compiler warning - (void) availableData; } void Ipv4RawSocketImplTest::ReceivePkt2 (Ptr socket) @@ -127,9 +124,6 @@ NS_ASSERT (m_receivedPacket2->GetSize () == 2); m_receivedPacket2 = socket->Recv (std::numeric_limits::max (), 0); NS_ASSERT (availableData == m_receivedPacket2->GetSize ()); - //cast availableData to void, to suppress 'availableData' set but not used - //compiler warning - (void) availableData; } void diff --git a/src/internet/test/udp-test.cc b/src/internet/test/udp-test.cc --- a/src/internet/test/udp-test.cc +++ b/src/internet/test/udp-test.cc @@ -94,9 +94,6 @@ availableData = socket->GetRxAvailable (); m_receivedPacket = socket->Recv (std::numeric_limits::max (), 0); NS_ASSERT (availableData == m_receivedPacket->GetSize ()); - //cast availableData to void, to suppress 'availableData' set but not used - //compiler warning - (void) availableData; } void @@ -155,9 +152,6 @@ availableData = socket->GetRxAvailable (); m_receivedPacket = socket->Recv (std::numeric_limits::max (), 0); NS_ASSERT (availableData == m_receivedPacket->GetSize ()); - //cast availableData to void, to suppress 'availableData' set but not used - //compiler warning - (void) availableData; } void UdpSocketImplTest::ReceivePkt2 (Ptr socket) @@ -166,9 +160,6 @@ availableData = socket->GetRxAvailable (); m_receivedPacket2 = socket->Recv (std::numeric_limits::max (), 0); NS_ASSERT (availableData == m_receivedPacket2->GetSize ()); - //cast availableData to void, to suppress 'availableData' set but not used - //compiler warning - (void) availableData; } void diff --git a/src/mobility/helper/ns2-mobility-helper.cc b/src/mobility/helper/ns2-mobility-helper.cc --- a/src/mobility/helper/ns2-mobility-helper.cc +++ b/src/mobility/helper/ns2-mobility-helper.cc @@ -42,6 +42,7 @@ #include #include #include "ns3/log.h" +#include "ns3/unused.h" #include "ns3/simulator.h" #include "ns3/node-list.h" #include "ns3/node.h" @@ -446,8 +447,7 @@ { char *endp; double v = strtod (s.c_str (), &endp); // declared with warn_unused_result - //cast v to void, to suppress v set but not used compiler warning - (void) v; + NS_UNUSED (v); // suppress "set but not used" compiler warning return endp == s.c_str () + s.size (); } diff --git a/src/network/helper/trace-helper.h b/src/network/helper/trace-helper.h --- a/src/network/helper/trace-helper.h +++ b/src/network/helper/trace-helper.h @@ -94,7 +94,7 @@ template void PcapHelper::HookDefaultSink (Ptr object, std::string tracename, Ptr file) { - bool __attribute__ ((unused)) result = + bool result = object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultSink, file)); NS_ASSERT_MSG (result == true, "PcapHelper::HookDefaultSink(): Unable to hook \"" << tracename << "\""); } @@ -231,7 +231,7 @@ template void AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext (Ptr object, std::string tracename, Ptr file) { - bool __attribute__ ((unused)) result = + bool result = object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultEnqueueSinkWithoutContext, file)); NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext(): Unable to hook \"" << tracename << "\""); @@ -244,7 +244,7 @@ std::string tracename, Ptr stream) { - bool __attribute__ ((unused)) result = + bool result = object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultEnqueueSinkWithContext, stream)); NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultEnqueueSinkWithContext(): Unable to hook \"" << tracename << "\""); @@ -253,7 +253,7 @@ template void AsciiTraceHelper::HookDefaultDropSinkWithoutContext (Ptr object, std::string tracename, Ptr file) { - bool __attribute__ ((unused)) result = + bool result = object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultDropSinkWithoutContext, file)); NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithoutContext(): Unable to hook \"" << tracename << "\""); @@ -266,7 +266,7 @@ std::string tracename, Ptr stream) { - bool __attribute__ ((unused)) result = + bool result = object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDropSinkWithContext, stream)); NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDropSinkWithContext(): Unable to hook \"" << tracename << "\""); @@ -275,7 +275,7 @@ template void AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext (Ptr object, std::string tracename, Ptr file) { - bool __attribute__ ((unused)) result = + bool result = object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultDequeueSinkWithoutContext, file)); NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext(): Unable to hook \"" << tracename << "\""); @@ -288,7 +288,7 @@ std::string tracename, Ptr stream) { - bool __attribute__ ((unused)) result = + bool result = object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultDequeueSinkWithContext, stream)); NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultDequeueSinkWithContext(): Unable to hook \"" << tracename << "\""); @@ -297,7 +297,7 @@ template void AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext (Ptr object, std::string tracename, Ptr file) { - bool __attribute__ ((unused)) result = + bool result = object->TraceConnectWithoutContext (tracename, MakeBoundCallback (&DefaultReceiveSinkWithoutContext, file)); NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext(): Unable to hook \"" << tracename << "\""); @@ -310,7 +310,7 @@ std::string tracename, Ptr stream) { - bool __attribute__ ((unused)) result = + bool result = object->TraceConnect (tracename, context, MakeBoundCallback (&DefaultReceiveSinkWithContext, stream)); NS_ASSERT_MSG (result == true, "AsciiTraceHelper::HookDefaultReceiveSinkWithContext(): Unable to hook \"" << tracename << "\""); diff --git a/src/network/model/socket.cc b/src/network/model/socket.cc --- a/src/network/model/socket.cc +++ b/src/network/model/socket.cc @@ -314,9 +314,6 @@ } } NS_ASSERT_MSG (found, "Socket cannot be bound to a NetDevice not existing on the Node"); - //cast found to void, to suppress 'found' set but not used compiler warning - //in optimized builds - (void) found; } m_boundnetdevice = netdevice; return; diff --git a/src/network/utils/packet-socket.cc b/src/network/utils/packet-socket.cc --- a/src/network/utils/packet-socket.cc +++ b/src/network/utils/packet-socket.cc @@ -441,9 +441,6 @@ bool found; found = packet->PeekPacketTag (tag); NS_ASSERT (found); - //cast found to void, to suppress 'found' set but not used compiler warning - //in optimized builds - (void) found; fromAddress = tag.GetAddress (); } return packet; diff --git a/src/network/utils/radiotap-header.cc b/src/network/utils/radiotap-header.cc --- a/src/network/utils/radiotap-header.cc +++ b/src/network/utils/radiotap-header.cc @@ -134,7 +134,7 @@ { NS_LOG_FUNCTION (this); - uint8_t __attribute__ ((unused)) tmp = start.ReadU8 (); // major version of radiotap header + uint8_t tmp = start.ReadU8 (); // major version of radiotap header NS_ASSERT_MSG (tmp == 0x00, "RadiotapHeader::Deserialize(): Unexpected major version"); start.ReadU8 (); // pad field diff --git a/src/test/ns3wifi/wifi-interference-test-suite.cc b/src/test/ns3wifi/wifi-interference-test-suite.cc --- a/src/test/ns3wifi/wifi-interference-test-suite.cc +++ b/src/test/ns3wifi/wifi-interference-test-suite.cc @@ -77,16 +77,23 @@ { } -void -WifiInterferenceTestCase::ReceivePacket (Ptr socket) +std::string +PrintReceivedPacket (Ptr socket) { Address addr; socket->GetSockName (addr); InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (addr); - NS_LOG_UNCOND ("Received one packet! Socket: " << iaddr.GetIpv4 () << " port: " << iaddr.GetPort ()); - //cast iaddr to void, to suppress 'iaddr' set but not used compiler warning - //in optimized builds - (void) iaddr; + + std::ostringstream oss; + oss << "Received one packet! Socket: " << iaddr.GetIpv4 () << " port: " << iaddr.GetPort (); + + return oss.str (); +} + +void +WifiInterferenceTestCase::ReceivePacket (Ptr socket) +{ + NS_LOG_UNCOND (PrintReceivedPacket (socket)); } void diff --git a/src/topology-read/model/rocketfuel-topology-reader.cc b/src/topology-read/model/rocketfuel-topology-reader.cc --- a/src/topology-read/model/rocketfuel-topology-reader.cc +++ b/src/topology-read/model/rocketfuel-topology-reader.cc @@ -25,6 +25,7 @@ #include #include "ns3/log.h" +#include "ns3/unused.h" #include "rocketfuel-topology-reader.h" namespace ns3 { @@ -76,6 +77,18 @@ int nodesNumber = 0; std::map > nodeMap; +void +PrintNodeInfo (std::string & uid, std::string & loc, bool dns, bool bb, + std::vector ::size_type neighListSize, + std::string & name, int radius) +{ + /* uid @loc [+] [bb] (num_neigh) [&ext] -> ... {-euid} ... =name[!] rn */ + NS_LOG_INFO ("Load Node[" << uid << "]: location: " << loc << " dns: " << dns + << " bb: " << bb << " neighbors: " << neighListSize + << "(" << "%d" << ") externals: \"%s\"(%d) " + << "name: " << name << " radius: " << radius); +} + NodeContainer RocketfuelTopologyReader::GenerateFromMapsFile (int argc, char *argv[]) { @@ -150,16 +163,7 @@ return nodes; } - /* uid @loc [+] [bb] (num_neigh) [&ext] -> ... {-euid} ... =name[!] rn */ - NS_LOG_INFO ("Load Node[" << uid << "]: location: " << loc << " dns: " << dns - << " bb: " << bb << " neighbors: " << neigh_list.size () - << "(" << "%d" << ") externals: \"%s\"(%d) " - << "name: " << name << " radius: " << radius); - - //cast bb and dns to void, to suppress variable set but not used compiler warning - //in optimized builds - (void) bb; - (void) dns; + PrintNodeInfo (uid, loc, dns, bb, neigh_list.size (), name, radius); // Create node and link if (!uid.empty ()) @@ -209,8 +213,7 @@ sname = argv[0]; tname = argv[1]; double v = strtod (argv[2], &endptr); // weight - // cast v to void , to suppress 'v' set but not used compiler warning - (void) v; + NS_UNUSED (v); // suppress "set but not used" compiler warning in optimized builds if (*endptr != '\0') { NS_LOG_WARN ("invalid weight: " << argv[2]); diff --git a/src/wifi/model/wifi-information-element.cc b/src/wifi/model/wifi-information-element.cc --- a/src/wifi/model/wifi-information-element.cc +++ b/src/wifi/model/wifi-information-element.cc @@ -55,9 +55,6 @@ // This IE was not optional, so confirm that we did actually // deserialise something. NS_ASSERT (i.GetDistanceFrom (start) != 0); - // cast start to void, to suppress ‘start’ set but not used - // compiler warning in optimized builds - (void) start; return i; } diff --git a/src/wifi/model/wifi-remote-station-manager.cc b/src/wifi/model/wifi-remote-station-manager.cc --- a/src/wifi/model/wifi-remote-station-manager.cc +++ b/src/wifi/model/wifi-remote-station-manager.cc @@ -368,9 +368,6 @@ bool found; found = ConstCast (packet)->PeekPacketTag (tag); NS_ASSERT (found); - // cast found to void, to suppress 'found' set but not used - // compiler warning - (void) found; return tag.GetDataMode (); } return DoGetDataMode (Lookup (address, header), fullPacketSize); @@ -386,9 +383,6 @@ bool found; found = ConstCast (packet)->PeekPacketTag (tag); NS_ASSERT (found); - // cast found to void, to suppress 'found' set but not used - // compiler warning - (void) found; return tag.GetRtsMode (); } return DoGetRtsMode (Lookup (address, header));