You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jeff Trawick <tr...@gmail.com> on 2011/03/25 21:42:02 UTC

aplog_module_index and C++

This is a constant pointer which is declared without initialization
like this in http_log.h:

static int * const aplog_module_index;

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.

Re: aplog_module_index and C++

Posted by Jeff Trawick <tr...@gmail.com>.
On Sat, Mar 26, 2011 at 8:32 AM, Jeff Trawick <tr...@gmail.com> wrote:
> On Fri, Mar 25, 2011 at 11:04 PM, William A. Rowe Jr.
> <wr...@rowe-clan.net> wrote:
>> On 3/25/2011 7:13 PM, Stefan Fritsch wrote:
>>>
>>> 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?
>>
>> +1, as long as the .h files are usable verbatim from .cpp sources, then
>> whatever specific magic is required for the .cpp modules to adopt the
>> logging constructs would make good sense, and be just a bit of extra
>> work for such developers.  It just needs documenting.
>
> Yeah, that's what I was planning.
>>
>> I'll test-build mod_aspdotnet (a c++ module) against trunk just as soon
>> as your proposed fix is committed.
>>
>
> Meanwhile I have another C++ module to practice with, hopefully using
> both g++ and Intel.  Maybe I can get that done today.

What I just committed works for me with g++ and icc.

icc points at APLOG_MARK and says "warning #279: controlling
expression is constant"

Since the default for aplog_module/index/APLOG_MODULE_INDEX is not
implemented for C++, we can change APLOG_MODULE_INDEX to the simpler

#define APLOG_MODULE_INDEX (*aplog_module_index)

for C++, which resolves that warning.

Re: aplog_module_index and C++

Posted by Jeff Trawick <tr...@gmail.com>.
On Fri, Mar 25, 2011 at 11:04 PM, William A. Rowe Jr.
<wr...@rowe-clan.net> wrote:
> On 3/25/2011 7:13 PM, Stefan Fritsch wrote:
>>
>> 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?
>
> +1, as long as the .h files are usable verbatim from .cpp sources, then
> whatever specific magic is required for the .cpp modules to adopt the
> logging constructs would make good sense, and be just a bit of extra
> work for such developers.  It just needs documenting.

Yeah, that's what I was planning.
>
> I'll test-build mod_aspdotnet (a c++ module) against trunk just as soon
> as your proposed fix is committed.
>

Meanwhile I have another C++ module to practice with, hopefully using
both g++ and Intel.  Maybe I can get that done today.

Re: aplog_module_index and C++

Posted by "William A. Rowe Jr." <wr...@rowe-clan.net>.
On 3/25/2011 7:13 PM, Stefan Fritsch wrote:
> 
> 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?

+1, as long as the .h files are usable verbatim from .cpp sources, then
whatever specific magic is required for the .cpp modules to adopt the
logging constructs would make good sense, and be just a bit of extra
work for such developers.  It just needs documenting.

I'll test-build mod_aspdotnet (a c++ module) against trunk just as soon
as your proposed fix is committed.

Re: aplog_module_index and C++

Posted by Stefan Fritsch <sf...@sfritsch.de>.
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?