On Friday 25 March 2011, Jeff Trawick wrote: > This is a constant pointer which is declared without initialization > like this in http_log.h: > > static int * const aplog_module_index;
This is a so called tentative definition in C. If there is a definition later on, this one is treated as a declaration. If not, it's treated as a definition (initializing to the default NULL). Unfortunately, C++ doesn't have a similar concept. > > Unfortunately that's not valid C++ since there is no initializer. > Three of the four C++ compilers I tried consider that a fatal > error. Unfortunately, as I guess Stefan knows, it is tricky to > make this work in C too, and there does't seem to be much leeway. > > Meanwhile, after removing "const" at least one of the C++ compilers > I'm trying generates a fatal error at the duplicate places > aplog_module_index is declared (when you use APLOG_USE_MODULE and > also include http_log.h). > > My gut feel is that to get along with the wide array of C and C++ > compilers out there we'll have to get less tricky, even if it means > a hard requirement to declare APLOG_USE_MODULE everywhere. There doesn't seem to be a way in C++ to declare a static variable without defining it. So my gut feeling is that your gut feeling is correct for C++. A possibility would be to put the tentative definition in http_log.h inside a #ifndef __cplusplus. In C, nothing would change. And in C++, one would have to set APLOG_USE_MODULE() before using any logging function. What do you think of that? Would that be too confusing?
