Re: Conditional compilation sans the cpp
From: lilburne (lilburne_at_godzilla.com)
Date: 08/18/04
- Next message: kamil: "Re: How to create an initialised object declared as a class member variable?"
- Previous message: Raghavendra Mahuli: "string parser"
- In reply to: Steven T. Hatton: "Re: Conditional compilation sans the cpp"
- Next in thread: Thomas Matthews: "Re: Conditional compilation sans the cpp"
- Reply: Thomas Matthews: "Re: Conditional compilation sans the cpp"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: kamil: "Re: How to create an initialised object declared as a class member variable?"
- Previous message: Raghavendra Mahuli: "string parser"
- In reply to: Steven T. Hatton: "Re: Conditional compilation sans the cpp"
- Next in thread: Thomas Matthews: "Re: Conditional compilation sans the cpp"
- Reply: Thomas Matthews: "Re: Conditional compilation sans the cpp"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|