Tsantilas Christos wrote:
> Hi Amos,
> Some comments about "#if X" and "#ifdef X".
> The gcc compiler when X is not defined, always assume that it is 0 when
> appeared in an "#if". So it is safe to use the #if instead of #ifdef.
> But maybe there is problem with other compilers (If I am not wrong
> visual c++ is an example).
Been a while since I used VSC++, but better safe than sorry in this anyway.
>
> Personaly I am confused when I have to use #if and #ifdef in squid.
> From what I can see squid prefers to use #if in most cases, but I
> believe this is not correct. The #ifdef should used when a preprocessor
> variable is defined or not defined and #if when it is 0 or not 0.
My belief matches yours. The problem is Squid inconsistent use of define
for these things. Which this RFC seeks to remedy.
I'm partial to changes that let use drop the #ifdef/#ifndef and allows
shorter define logics. AKA method (1).
But we have to work around autoconf which I think uses method (2) for
its HAVE_ defines and ours should be seamless with those.
> Amos Jeffries wrote:
>>
>> At present we have a little bit of a mess with the configure.in
>> defined macros.
>>
>> 1) defined or undefined.
>> For coding: #ifdef or #ifndef
>> Combined form: #if defined(X) && defined(Y) ...
>>
>> 2) always defined.
>> For coding: #if X
>> Combined form: #if X && Y ...
>>
>> I'm thinking the HAVE_ should be method (1) and the USE_ should be
>> method (2).
>>
>> Do we already have a formal policy somewhere I've missed?
>>
>> If we don't, Opinions on what to adopt?
>>
>>
>> Amos
>
This code built by gcc and g++:
#define ZERO 0
#define ONE 1
#define DEF
/* #undef UNDEF */
#if ZERO
#warning if ZERO = 1?
#endif
#if !ZERO
#warning if ZERO = 0?
#endif
#ifdef ZERO
#warning ifdef ZERO == defined
#endif
#ifndef ZERO
#warning ifndef ZERO == non-defined
#endif
#if ONE
#warning if ONE == 1?
#endif
#if !ONE
#warning if ONE == 0?
#endif
#ifdef ONE
#warning ifdef ONE == defined
#endif
#ifndef ONE
#warning ifndef ONE == non-defined
#endif
#if DEF
#warning if DEF == 1?
#endif
#if !DEF
#warning if DEF == 0?
#endif
#ifdef DEF
#warning ifdef DEF == defined
#endif
#ifndef DEF
#warning ifndef DEF == non-defined
#endif
#if UNDEF
#warning if UNDEF == 1?
#endif
#if !UNDEF
#warning if UNDEF == 0?
#endif
#ifdef UNDEF
#warning ifdef UNDEF == defined
#endif
#ifndef UNDEF
#warning ifndef UNDEF == non-defined
#endif
int main(int argc, char **argv) { return 0; }
Produces:
if ZERO = 0?
ifdef ZERO == defined
if ONE == 1?
ifdef ONE == defined
main.cc:34:8: error: #if with no expression
main.cc:37:9: error: operator '!' has no right operand
ifdef DEF == defined
if UNDEF == 0?
ifndef UNDEF == non-defined
Amos
-- Please be using Current Stable Squid 2.7.STABLE6 or 3.0.STABLE13 Current Beta Squid 3.1.0.6Received on Mon Mar 30 2009 - 10:01:58 MDT
This archive was generated by hypermail 2.2.0 : Mon Mar 30 2009 - 12:00:04 MDT