發現自己有warning強迫綜合徵
../Framework/src/network/net.cpp: In function ‘boolean NetGetIP(int8*)’:
../Framework/src/network/net.cpp:813: warning: dereferencing pointer ‘saddr’ does break strict-aliasing rules../Framework/src/network/net.cpp:812: note: initialized from here
../Framework/src/network/net.cpp: In member function ‘boolean Net::sOperaRoute(const int8*, const int8*, int32)’:
../Framework/src/network/net.cpp:436: warning: dereferencing pointer ‘<anonymous>’ does break strict-aliasing rules
../Framework/src/network/net.cpp:436: note: initialized from here
../Framework/src/network/net.cpp:441: warning: dereferencing pointer ‘<anonymous>’ does break strict-aliasing rules
../Framework/src/network/net.cpp:441: note: initialized from here
../Framework/src/network/net.cpp:446: warning: dereferencing pointer ‘<anonymous>’ does break strict-aliasing rules
./Framework/src/network/net.cpp:446: note: initialized from here
解決辦法
摘抄自網絡:
http://blog.chinaunix.net/uid-17019762-id-3152012.html
-
// 會出現warning 的代碼!
-
class cInit
-
{
-
public:
-
cInit(std::string str, int a) : str_(str), a_(a)
-
{ }
-
-
private:
-
int a_;
-
std::string str_;
- };
-
// OK
-
class cInit
-
{
-
public:
-
cInit(std::string str, int a) : str_(str), a_(a)
-
{ }
-
-
private:
-
std::string str_;
-
int a_;
- };