c++ - What means the error : ..."bytes to alignment boundary" in Xcode/Clang? -
transformnode 4 bytes alignment boundary
and here code cause warning :
class transformnode : public node { public: int number; public: void test() { number = 12; } }; //node.h class node { public: typedef std::set<node *> childset; protected: childset mchildren; node * mparent; public: node(node * parent=0) : mparent(parent) {} ~node() {} node * addchild(node * node); inline node * getparent() { return mparent; } const childset &getchildren() const { return mchildren; } }; inline void node_test() { transformnode * node = new transformnode; node->test(); std::cout << node->number << "\n"; } int main() { node_test(); return 0; }
the error happens when derive node class class transformnode. using xcode 5.0 warnings turned on , treating warnings errors. want understand going on code, turning off warnings or stop treating them errors not way want handle this.
edit: added more code. clarification on details (in bold)
thanks,
gasim
i'm not sure if you're seeing error. generally, "all warnings" includes kinds of stuff barely considered warnings; heck, part aren't super informative either.
alignment issue don't care unless you're working specific hardware in embedded system. happening compiler defaults 8-byte alignment, , when define transformnode
class, allocating 4 bytes int
, "wasting" 4 more bytes align entire class 8-byte boundary. compiler warning telling "wasted" 4 bytes. said, not care this.
i think in general you'll drive mad if have maximal warnings , warnings-as-errors turned on. more useful step 1 level of warning , treat error if want super-clean.
reedit: clarified answer in light of recent edits.
another thought: try adding int
in transformnode
class , see if warning goes away (i'm assuming because int
#2 "use up" "wasted" 4 bytes).
you can check out http://en.wikipedia.org/wiki/data_padding understand issue better.
Comments
Post a Comment