[geos-devel] assert.h / assert()

Mateusz Łoskot mateusz at loskot.net
Tue Jan 31 18:53:38 EST 2006


strk at refractions.net wrote:
> Is there any known problem in using assert.h with GEOS ?

I don't know any problems with using assert() macro but it should be 
included from <cassert> header in C++.

Most popular debugging tool defined by C++ Standard is assert() macro.
As C++ Standard says (17.4.1.2) it should be defined as macro, even if
some C implementations define assert() as a function.

In order to make things more clear, C++ Standard uses c prefix (cname) 
for every header provided by Standard C Library. Also, C++ Standard says 
"the contents of each header cname shall be the same as that of the 
corresponding header name.h, as specified in ISO/IEC 9899:1990 
Programming Languages C"

But the very important note is that:
"In the C++ Standard Library, however, the declarations and definitions 
(except for names which are defined as macros in C) are within namespace 
scope (3.3.5) of the namespace std."

According to the note above, assert() macro from <cassert> header is not 
placed in std namespace. The rest of contents from <cstdio>, <cstdlib> 
etc. is placed in std namespace.

Finally, the contents of assert.h and cassert is the same, both declare 
macro named assert(). But for better ANSI/ISO C++ compliance it's 
recommended to use <cassert> in C++ programs.

Besides assert() macro, C++ Standard defines exceptions and error 
numbers (just as in C).

 > I'm asking
 > as I know there have been issues with stdio.h in the past, but I'd
 > like to be able using assert() or any equivalent standard C++ thing
 > to easy debugging.

I don't know what problems you are talking about but I suppose they were 
related to std namespace and stdio and <cstdio>.

Cheers
-- 
Mateusz Łoskot
http://mateusz.loskot.net



More information about the geos-devel mailing list