does break strict-aliasing rules

發現自己有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

  1. // 會出現warning 的代碼!
  2. class cInit
  3. {
  4. public:
  5.     cInit(std::string str, int a) : str_(str), a_(a)
  6.     { }

  7. private:
  8.     int a_;
  9.     std::string str_;
  10. };


  1. // OK
  2. class cInit
  3. {
  4. public:
  5.     cInit(std::string str, int a) : str_(str), a_(a)
  6.     { }

  7. private:
  8.     std::string str_;
  9.     int a_;
  10. };


發佈了107 篇原創文章 · 獲贊 35 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章