From cec21ade4348085360931d41b660a3e61273a2ff Mon Sep 17 00:00:00 2001 From: Andrey Mazo Date: Fri, 10 Feb 2012 19:02:12 +0400 Subject: [PATCH] Bug 1170: Formulate best practices for dealing with unused debug variables. --- examples/energy/energy-model-example.cc | 22 ++++++--- examples/routing/manet-routing-compare.cc | 40 ++++++++------- examples/stats/wifi-example-apps.h | 2 - examples/stats/wifi-example-sim.cc | 2 - examples/wireless/multirate.cc | 49 ++++++++++--------- examples/wireless/wifi-simple-interference.cc | 16 ++++-- src/applications/model/packet-sink.cc | 19 ++++--- src/applications/model/v4ping.cc | 3 -- .../helper/click-internet-stack-helper.cc | 7 ++- src/click/test/ipv4-click-routing-test.cc | 9 ---- src/core/examples/main-callback.cc | 11 ++--- src/core/model/assert.h | 15 +++++- src/core/model/unused.h | 8 +++ src/core/wscript | 3 +- src/internet/helper/internet-stack-helper.cc | 14 ++---- src/internet/model/ipv6-l3-protocol.cc | 2 - src/internet/model/nsc-tcp-socket-impl.cc | 3 -- src/internet/model/udp-socket-impl.cc | 3 -- src/internet/test/ipv4-fragmentation-test.cc | 1 - src/internet/test/ipv4-header-test.cc | 3 -- src/internet/test/ipv4-raw-test.cc | 6 --- src/internet/test/udp-test.cc | 9 ---- src/mobility/helper/ns2-mobility-helper.cc | 4 +- src/network/helper/trace-helper.h | 18 +++---- src/network/model/socket.cc | 3 -- src/network/utils/packet-socket.cc | 3 -- src/network/utils/radiotap-header.cc | 2 +- .../ns3wifi/wifi-interference-test-suite.cc | 19 ++++--- .../model/rocketfuel-topology-reader.cc | 27 +++++----- src/wifi/model/wifi-information-element.cc | 3 -- src/wifi/model/wifi-remote-station-manager.cc | 6 --- 31 files changed, 163 insertions(+), 169 deletions(-) create mode 100644 src/core/model/unused.h diff --git a/examples/energy/energy-model-example.cc b/examples/energy/energy-model-example.cc index 8f0037e43..0b9c78586 100644 --- a/examples/energy/energy-model-example.cc +++ b/examples/energy/energy-model-example.cc @@ -35,6 +35,20 @@ NS_LOG_COMPONENT_DEFINE ("EnergyExample"); 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 @@ ReceivePacket (Ptr socket) { 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 index e2ffd74bc..d07bef11f 100644 --- a/examples/routing/manet-routing-compare.cc +++ b/examples/routing/manet-routing-compare.cc @@ -117,6 +117,28 @@ RoutingExperiment::RoutingExperiment () { } +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 @@ RoutingExperiment::ReceivePacket (Ptr socket) { 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 index 862efac93..653a17599 100644 --- 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 index 05f30aead..d9171c23b 100644 --- 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 index 65a643f43..c70f79189 100644 --- a/examples/wireless/multirate.cc +++ b/examples/wireless/multirate.cc @@ -89,7 +89,6 @@ public: private: - Vector GetPosition (Ptr node); Ptr SetupPacketReceive (Ptr node); NodeContainer GenerateNeighbors (NodeContainer c, uint32_t senderId); @@ -181,13 +180,6 @@ Experiment::CheckThroughput () 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 @@ Experiment::SendMultiDestinations (Ptr sender, NodeContainer c) } } -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 @@ Experiment::ApplicationSetup (Ptr client, Ptr server, double start, 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 index fab85ba36..59eadb9e4 100644 --- a/examples/wireless/wifi-simple-interference.cc +++ b/examples/wireless/wifi-simple-interference.cc @@ -96,15 +96,21 @@ NS_LOG_COMPONENT_DEFINE ("WifiSimpleInterference"); 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 index 57b817727..4d4288208 100644 --- a/src/applications/model/packet-sink.cc +++ b/src/applications/model/packet-sink.cc @@ -151,6 +151,17 @@ void PacketSink::StopApplication () // Called at time specified by Stop } } +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 @@ void PacketSink::HandleRead (Ptr socket) 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 index 386cc46c6..5201c0e30 100644 --- a/src/applications/model/v4ping.cc +++ b/src/applications/model/v4ping.cc @@ -243,9 +243,6 @@ V4Ping::StartApplication (void) 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 index 1a4d6996e..045c843a9 100644 --- a/src/click/helper/click-internet-stack-helper.cc +++ b/src/click/helper/click-internet-stack-helper.cc @@ -297,7 +297,6 @@ ClickInternetStackHelper::EnablePcapIpv4Internal (std::string prefix, Ptr 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 @@ ClickInternetStackHelper::EnableAsciiIpv4Internal ( // 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 index d647018e9..502c3162c 100644 --- a/src/click/test/ipv4-click-routing-test.cc +++ b/src/click/test/ipv4-click-routing-test.cc @@ -97,9 +97,6 @@ ClickIfidFromNameTest::DoRun () 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 @@ ClickIpMacAddressFromNameTest::DoRun () 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 @@ ClickTrivialTest::DoRun () 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 index 713bdd63f..1fb3f167a 100644 --- a/src/core/examples/main-callback.cc +++ b/src/core/examples/main-callback.cc @@ -34,9 +34,8 @@ int main (int argc, char *argv[]) // 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 @@ int main (int argc, char *argv[]) // 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 index 34e38c27c..9ecde44ed 100644 --- 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 index 000000000..c7b294003 --- /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 index 3066e92f1..a313a7237 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -240,7 +240,8 @@ def build(bld): '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 index 5aa8656e7..3ebc5e6df 100644 --- a/src/internet/helper/internet-stack-helper.cc +++ b/src/internet/helper/internet-stack-helper.cc @@ -492,9 +492,6 @@ InternetStackHelper::EnablePcapIpv4Internal (std::string prefix, Ptr ipv4, 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 @@ InternetStackHelper::EnablePcapIpv6Internal (std::string prefix, Ptr ipv6, 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 @@ InternetStackHelper::EnableAsciiIpv4Internal ( // 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 @@ InternetStackHelper::EnableAsciiIpv6Internal ( // 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 index e33cd3dc5..ce0ccf65c 100644 --- a/src/internet/model/ipv6-l3-protocol.cc +++ b/src/internet/model/ipv6-l3-protocol.cc @@ -969,9 +969,7 @@ void Ipv6L3Protocol::LocalDeliver (Ptr packet, Ipv6Header const& i 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 index 69a816917..389658083 100644 --- a/src/internet/model/nsc-tcp-socket-impl.cc +++ b/src/internet/model/nsc-tcp-socket-impl.cc @@ -449,9 +449,6 @@ NscTcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, 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 index 9d806f33a..1442c7745 100644 --- a/src/internet/model/udp-socket-impl.cc +++ b/src/internet/model/udp-socket-impl.cc @@ -547,9 +547,6 @@ UdpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, 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 index db5930316..e0f0e66e2 100644 --- 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 index 96fcc44dc..8fd5f365d 100644 --- a/src/internet/test/ipv4-header-test.cc +++ b/src/internet/test/ipv4-header-test.cc @@ -105,9 +105,6 @@ void Ipv4HeaderTest::ReceivePkt (Ptr socket) 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 index ed8e999ee..10ee506be 100644 --- a/src/internet/test/ipv4-raw-test.cc +++ b/src/internet/test/ipv4-raw-test.cc @@ -114,9 +114,6 @@ void Ipv4RawSocketImplTest::ReceivePkt (Ptr socket) 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 @@ void Ipv4RawSocketImplTest::ReceivePkt2 (Ptr socket) 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 index 418a27dc8..d8efbbc81 100644 --- a/src/internet/test/udp-test.cc +++ b/src/internet/test/udp-test.cc @@ -94,9 +94,6 @@ void UdpSocketLoopbackTest::ReceivePkt (Ptr socket) 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 @@ void UdpSocketImplTest::ReceivePkt (Ptr socket) 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 @@ void UdpSocketImplTest::ReceivePkt2 (Ptr socket) 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 index 155056029..25c3717ca 100644 --- 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 @@ IsNumber (const string& s) { 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 index d359d5b0e..7d03875ca 100644 --- a/src/network/helper/trace-helper.h +++ b/src/network/helper/trace-helper.h @@ -94,7 +94,7 @@ private: 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 @@ public: 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 @@ AsciiTraceHelper::HookDefaultEnqueueSinkWithContext ( 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 @@ AsciiTraceHelper::HookDefaultEnqueueSinkWithContext ( 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 @@ AsciiTraceHelper::HookDefaultDropSinkWithContext ( 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 @@ AsciiTraceHelper::HookDefaultDropSinkWithContext ( 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 @@ AsciiTraceHelper::HookDefaultDequeueSinkWithContext ( 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 @@ AsciiTraceHelper::HookDefaultDequeueSinkWithContext ( 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 @@ AsciiTraceHelper::HookDefaultReceiveSinkWithContext ( 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 index 84927a3a5..722a90691 100644 --- a/src/network/model/socket.cc +++ b/src/network/model/socket.cc @@ -314,9 +314,6 @@ Socket::BindToNetDevice (Ptr netdevice) } } 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 index 9f5acc2b5..ab9904b8f 100644 --- a/src/network/utils/packet-socket.cc +++ b/src/network/utils/packet-socket.cc @@ -441,9 +441,6 @@ PacketSocket::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress) 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 index ec880a3c3..dcde79dd5 100644 --- a/src/network/utils/radiotap-header.cc +++ b/src/network/utils/radiotap-header.cc @@ -134,7 +134,7 @@ RadiotapHeader::Deserialize (Buffer::Iterator start) { 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 index 33de052a0..69bdcd991 100644 --- a/src/test/ns3wifi/wifi-interference-test-suite.cc +++ b/src/test/ns3wifi/wifi-interference-test-suite.cc @@ -77,16 +77,23 @@ WifiInterferenceTestCase::~WifiInterferenceTestCase () { } -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 index ec7eada25..d0481488e 100644 --- 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 linksNumber = 0; 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 @@ RocketfuelTopologyReader::GenerateFromMapsFile (int argc, char *argv[]) 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 @@ RocketfuelTopologyReader::GenerateFromWeightsFile (int argc, char *argv[]) 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 index 05a338aeb..c5bfb9752 100644 --- a/src/wifi/model/wifi-information-element.cc +++ b/src/wifi/model/wifi-information-element.cc @@ -55,9 +55,6 @@ WifiInformationElement::Deserialize (Buffer::Iterator i) // 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 index ebbeeda7d..d2c9261e0 100644 --- a/src/wifi/model/wifi-remote-station-manager.cc +++ b/src/wifi/model/wifi-remote-station-manager.cc @@ -368,9 +368,6 @@ WifiRemoteStationManager::GetDataMode (Mac48Address address, const WifiMacHeader 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 @@ WifiRemoteStationManager::GetRtsMode (Mac48Address address, const WifiMacHeader 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));