c++ - How to best safeguard against mismatch of (compiler) flags between library (source) and application (header) compilations? -
While implementing some interfaces, as given in the header file, how to distinguish between a combination of library implementation Prevent header file?
  Description : A library is provided by the interface header file, say,   Then offset of    A solution?  Therefore, I have come up with the following idea    and    With the idea that    Question  Is the best way to deal with this type of problem?      I hope there is a better way, but you always place class or namespace based on options Can change the name so that if someone uses the wrong compiler option - then the class will not be found.    It is better to change the namespace name - this will not cause much confusion when using the debugger:    I think this will work, but it's definitely ugly.    foo.h , and its implementation by some source file, say ,  foo.cc . The latter has been compiled to create a library, say,  libfoo.so , while the former  # written by an application & lt; & Gt;  ed, which is the  libfoo. . . .    
 // foo.h namespace foo {class bar {# ifdef SomeOption std :: int32_t x [2]; # Als std :: int64_t x [2]; #endif bar const * ptr; / * ... * /}; }    ptr  is either 8 or 16 bytes, which depends on  SomeOption  (and  Sizeof (also bar))  is also different). Now, if the library was compiled with a different value from the app for  SomeOption , then obviously the serious problem will arise (which is difficult to debug for unknown).   
 // namespace foo {enum {hasSomeOption = 1}; Int options_flags () {return 0 #ifdef SomeOption | Hesomoison #ndif; } Class bar {/ * ... as before / bar (some_args, int); Public: Bar (some_args): Bar (some_args, options_flags ()) {} // what's option_flags ()? / * ... * /}; }    
 // foo.cc namespace {const int src_flags = options_flags (); // flag_name} fo {bar :: bar (some_args, int app_flags) {loud (app_flags == src_flags) used to compile library source; / * ... * /}}    emphasis  will catch any incompatibility, however, it does not work: compiler is my Ideas seem to be favorable and are never triggered, even if  SomeOption  was different for library and application compilation.   
 #ifdef SomeOption #define foo foo_32bit #else #define foo foo_64bit #endif namespace foo {....}   
 
  
Comments
Post a Comment