Precision Related Error in C++ -
while building software getting error:
../src/internet/model/nampt-socket.cc: in member function ‘ns3::ptr<ns3::namptsubflow> ns3::namptsocket::switchtomultipathmode()’: ../src/internet/model/nampt-socket.cc:881:14: error: cast ‘ns3::namptsocket*’ ‘uint32_t {aka unsigned int}’ loses precision [-fpermissive] (uint32_t)this, ^ waf: leaving directory `/home/vikas/ns-allinone-3.14.1/ns-3.14.1/build' build failed -> task in 'ns3-internet' failed (exit status 1): {task 140476688662992: cxx nampt-socket.cc -> nampt-socket.cc.1.o} ['/usr/bin/g++', '-o0', '-ggdb', '-g3', '-wall', '-werror', '-wno-error=deprecated-declarations', '-fstrict-aliasing', '-wstrict-aliasing', '-fpic', '-pthread', '-ibuild', '-i.', '-dns3_assert_enable', '-dns3_log_enable', '-dsqlite3=1', '-dhave_if_tun_h=1', '-denable_gsl', '../src/internet/model/nampt-socket.cc', '-c', '-o', 'src/internet/model/nampt-socket.cc.1.o'] traceback (most recent call last): file "./build.py", line 214, in <module> sys.exit(main(sys.argv)) file "./build.py", line 205, in main build_ns3(config, build_examples, build_tests, args, build_options) file "./build.py", line 98, in build_ns3 run_command([sys.executable, "waf", "build"] + build_options) file "/home/vikas/ns-allinone-3.14.1/util.py", line 24, in run_command raise commanderror("command %r exited code %i" % (argv, retval)) util.commanderror: command ['/usr/bin/python', 'waf', 'build'] exited code 1
the error :
cast ‘ns3::namptsocket*’ ‘uint32_t {aka unsigned int}’ loses precision [-fpermissive]
i searched error using uintptr_t not possible in case. other solution possible ?
the code error comes is:
ptr<namptsubflow> namptsocket::switchtomultipathmode(void) { ns_assert(m_firstsocket != 0); ns_assert(m_firstsocket->m_state == syn_sent || m_firstsocket->m_state == syn_rcvd); ns_assert(m_firstsocket->m_shellsocket == this); // change namptcc // original socket discarded m_tcp->m_sockets m_sockettypeid = namptcc::gettypeid(); m_firstsocket = namptsocket::convertcongestioncontrol(m_firstsocket); // subflow ptr<namptsubflow> sf = setupsubflow(m_firstsocket, true); sf->m_bbypasssending = true; ns_assert(sf->m_basesocket == m_firstsocket); // session name: time-socket-src-des if (m_timetag == 0) m_timetag = simulator::now().getseconds(); char buf[128]; snprintf(buf, 128, "%.6f-%08x-%u.%u.%u.%u->%u.%u.%u.%u", m_timetag, (uint32_t)this, (sf->m_localaddress.get() >> 24)&0x000000ff, (sf->m_localaddress.get() >> 16)&0x000000ff, (sf->m_localaddress.get() >> 8)&0x000000ff, (sf->m_localaddress.get() )&0x000000ff, (sf->m_peeraddress.get() >> 24)&0x000000ff, (sf->m_peeraddress.get() >> 16)&0x000000ff, (sf->m_peeraddress.get() >> 8)&0x000000ff, (sf->m_peeraddress.get() )&0x000000ff ); m_sessionname = buf; // init connection m_localport = m_firstsocket->m_endpoint->getlocalport(); m_peerport = m_firstsocket->m_endpoint->getpeerport(); m_nexttx = m_firstsocket->m_nexttxsequence; m_nexttx ++; // syn consumes 1 byte m_inputqueue.setheadsequence(m_nexttx); // next used addr addressset_t::const_iterator = m_addresses.find(sf->m_localaddress.get()); it++; if (it == m_addresses.end() ) = m_addresses.begin(); m_nextaddr = it->first; // m_outputqueue initialized after function returns. m_firstsocket = 0; // important... return sf; }
i believe correct way printf pointer use %p. want change code this:
snprintf(buf, 128, "%.6f-%p-%u.%u.%u.%u->%u.%u.%u.%u", m_timetag, (void *)this, (sf->m_localaddress.get() >> 24)&0x000000ff, (sf->m_localaddress.get() >> 16)&0x000000ff, (sf->m_localaddress.get() >> 8)&0x000000ff, (sf->m_localaddress.get() )&0x000000ff, (sf->m_peeraddress.get() >> 24)&0x000000ff, (sf->m_peeraddress.get() >> 16)&0x000000ff, (sf->m_peeraddress.get() >> 8)&0x000000ff, (sf->m_peeraddress.get() )&0x000000ff );
this avoids need cast kind of integer. %p formats in hexadecimal while avoiding need specify field size in printf statement. automatically adjust size when compiling 32-bit or 64-bit.
Comments
Post a Comment