This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 3.0.1 Freeze


On Tuesday 07 August 2001 02:21, Mark Mitchell wrote:
>   1. Build a generic std_limits.h that has a structure like:
>
>      #ifndef __glibcpp_int_bits
>      #define __glibcpp_int_bits 32
>      #endif
>
>      #if __glibcpp_int_bits == 32
>      #ifndef __glibcpp_int_max
>      #define __glibcpp_int_max <right value>
>      #endif
>      #ifndef __glibcpp_long_max
>      #define __glibcpp_long_max <right value>
>      #endif
>      ...
>      #elif __glibcpp_int_bits == 64
>      ...
>      #endif
>
>      <stuff involving __glibcpp_long_max>

Why is it that most of you insist on macros instead of const ints? Afaik gcc 
will generate the exact same code for:

#ifndef __architecture_defines_stuff_itself
#if __pointer_size == 32

const int __glibcpp_int_max = <right value>
const int __glibcpp_long_max = <right value>

#elif __pointer_size == 64
...
#endif
#endif

I would really like it if someone made a holy quest out of changing macros to 
functions or constants. Beginnning with gcc code is so much more difficult 
just for this one coding style question.

The only thing that's good about a macro is that you can override it. This is 
IMHO also the biggest problem with it. Especially #undef _X_; #define _X_ 
should be avoided like plague because it opens up for changing constants. In 
favour of constants are better debugging, backtrace in functions, no MAX(i++, 
j++) problem (examples borrowed from Effective C++, item 1). Macros are 
definately not always bad, but in case they could be avoided, they should be.

Note that Marks code here was just used as an example. It's definately not 
the worst example. One I have found to be a PITA is ASM_OUTPUT_MI_THUNK in 
config/i386/unix.h and others like it. Would a patch for changing this one be 
accepted, if it handled all necessary architectures?

Bo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]