Re: Conditional compilation sans the cpp

From: lilburne (lilburne_at_godzilla.com)
Date: 08/18/04


Date: Wed, 18 Aug 2004 11:56:53 +0100


Steven T. Hatton wrote:

> lilburne wrote:
>
>
>>int sort(class Collection& col, sortType type)
>>{
>> // sort the collection some how
>> ...
>>
>> DEBUG_FUNC(check_sorted(col,type));
>>}
>>
>>is less clutter than:
>>
>>int sort(class Collection& col, sortType type)
>>{
>> // sort the collection some how
>> ...
>>
>> if (DEBUG_FUNC) {
>> check_sorted(col,type);
>> }
>
>
> This form is more consitant with C++, more immediately intelligible, and
> doesn't require the code to be modified behind my back. If you are really
> concerned about clutter you could do this:
>
> if (DEBUG_FUNC) {check_sorted(col,type);}
>
> Or depending on its return type:
>
> if (DEBUG_FUNC && check_sorted(col, type){}
>

To say that the rewrite you habe given reduces clutter you can't have
had the privilege of looking at functions that have these
DEBUG_FUNC(...) statements every two or three lines.

>>and you still have the problem of how to get the compiler to know that
>>DEBUG_FUNC is always false?
>
>
> const DEBUG_FUNC=false;
>

How do you get that into the program? By having different headers, or by
editing a header? If the former how do you choose between the headers?
If the later how do you deal with the recompilation of 100s of source files?

>>Then there is also <cassert> or your favourite replacement.
>
>
> I'm not really sure why I need those. What does assert give me that I can't
> get from native C++?

Earlier you were discussing rectangles and points. The nearest thing we
have is a 3d box. This is the code for returning what we consider the
maximum point of a 3d box, which is pretty typical of our 'one-line'
functions:

Point3D Box3D::max() const
{
   ASSERT_STATE(!invalid(),"Box3D::max");
   ASSERT_STATE(m_arr[1][0] < infinity(),"Box3D::max | infinite");
   ASSERT_STATE(m_arr[1][1] < infinity(),"Box3D::max | infinite");
   ASSERT_STATE(m_arr[1][2] < infinity(),"Box3D::max | infinite");)
   return Point3D(m_arr[1][0],m_arr[1][1],m_arr[1][2]);
}

>
> Stroustrup's comment in §24.3.7.2 regarding the use of NDEBUG in conjunction
> with /assert/ is: "Like all macro magic, this use of NDEBUG is too
> low-level, messy, and error-prone.

Anyone not using /assert/ has messy, error-prone code.

> A simple example of what is fundamentally wrong with C++'s reliance on the
> #include <header> approach is when I tried using /size_t/ in a translation
> unit that didn't #include anything else from the Standard Library. It was
> undefined. The way I found it was to look it up in ISO/IEC 14882:2003 and
> discovered it is defined in #include <cstddef>. The fact that /size_t/ had
> always been available without my #including <cstddef> means there are
> multiple paths through the headers that can result in such identifiers
> being introduced into my code silently. That is a bad thing. It leads to
> dependencies on things I am not aware of. THAT DOESN'T SCALE!

Well there are many projects applications that contain 1,000,000s of
lines of code. The application I work on has about 10,000,000. Defines
in header files and conditional compilations really aren't a problem.



Relevant Pages

  • Re: .h for standard headers
    ... So you *are* telling me that I have bad work habits, ... With the C headers, I can grep all of them with no fear of ... defined my problem in terms of "clutter" and "abuse" I see ...
    (comp.lang.cpp)
  • OT Trying OE to post
    ... With Forte I could ... delete headers after reading to reduce clutter but don't see the option to ...
    (microsoft.public.windowsxp.general)
  • Re: #include "string.h"
    ... '3' is a paragraph number. ... of the standard places that are searched for included source files, ... What does "standard places" mean here? ... the same places that are searched for headers by a #include ...
    (comp.std.c)
  • Re: How to scan C files to find the required include files ?
    ... >files for c source files. ... Comment out all headers that are internal in the botom source. ... Compile the files at the bottom of the internal dependency graph. ... etc)/Perl/Python/Ruby script to do this. ...
    (comp.unix.programmer)
  • Re: #include "string.h"
    ... of the standard places that are searched for included source files, ... What does "standard places" mean here? ... the same places that are searched for headers by a #include ... inclusion", not "Source file inclusion and headers" or something. ...
    (comp.std.c)