473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

assert from <cassert>

Hi,

why can I use assert from <cassert> without resolving the std::
namespace? E.g.:

#include <cassert>

int main()
{
assert(true); // shouldn't this be: std::assert(true) ?
}

This compiles. I thought in the <c****> headers the macros are undef'ed
and replaced in favor of inline functions which reside in the std
namespace? In this case my program shouldn't compile. I'm using g++ 3.3.5.

--
Matthias Kaeppler
Jul 23 '05 #1
13 5379
Matthias Kaeppler wrote:
why can I use assert from <cassert> without resolving the std::
namespace? E.g.:

#include <cassert>

int main()
{
assert(true); // shouldn't this be: std::assert(true) ?
}

This compiles. I thought in the <c****> headers the macros are undef'ed
and replaced in favor of inline functions which reside in the std
namespace? In this case my program shouldn't compile. I'm using g++ 3.3.5.


'assert' is a macro, not a function.

V
Jul 23 '05 #2
Matthias Kaeppler wrote:
why can I use assert from <cassert> without resolving the std::
namespace? E.g.:

#include <cassert>

int main()
{
assert(true); // shouldn't this be: std::assert(true) ?
It's a #define macro.
}


(You might get in the habit of reading those header files...)

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #3
Victor Bazarov wrote:
Matthias Kaeppler wrote:
why can I use assert from <cassert> without resolving the std::
namespace? E.g.:

#include <cassert>

int main()
{
assert(true); // shouldn't this be: std::assert(true) ?
}

This compiles. I thought in the <c****> headers the macros are
undef'ed and replaced in favor of inline functions which reside in the
std namespace? In this case my program shouldn't compile. I'm using
g++ 3.3.5.


'assert' is a macro, not a function.

V


If it hasn't been replaced by an inline function (like many other
macros), what's the point of the <cassert> header?

--
Matthias Kaeppler
Jul 23 '05 #4
Matthias Kaeppler wrote:
Victor Bazarov wrote:
Matthias Kaeppler wrote:
why can I use assert from <cassert> without resolving the std::
namespace? E.g.:

#include <cassert>

int main()
{
assert(true); // shouldn't this be: std::assert(true) ?
}

This compiles. I thought in the <c****> headers the macros are
undef'ed and replaced in favor of inline functions which reside in
the std namespace? In this case my program shouldn't compile. I'm
using g++ 3.3.5.


'assert' is a macro, not a function.

V

If it hasn't been replaced by an inline function (like many other
macros), what's the point of the <cassert> header?


I don't understand the question, I guess. What do you mean "what's the
point"? There are no Standard C++ headers with .h in them. The existence
of old .h headers is a compatibility requirement and those features
(listed in Annex D, BTW) have been deprecated. Now, things that are
macros in C are still macros in C++, see 17.4.1.2/5. The C++ Standard
_allows_ their implementation as functions but doesn't *mandate* it.

V
Jul 23 '05 #5
Victor Bazarov wrote:
Matthias Kaeppler wrote:
Victor Bazarov wrote:
Matthias Kaeppler wrote:

why can I use assert from <cassert> without resolving the std::
namespace? E.g.:

#include <cassert>

int main()
{
assert(true); // shouldn't this be: std::assert(true) ?
}

This compiles. I thought in the <c****> headers the macros are
undef'ed and replaced in favor of inline functions which reside in
the std namespace? In this case my program shouldn't compile. I'm
using g++ 3.3.5.
'assert' is a macro, not a function.

V


If it hasn't been replaced by an inline function (like many other
macros), what's the point of the <cassert> header?

I don't understand the question, I guess. What do you mean "what's the
point"? There are no Standard C++ headers with .h in them. The existence
of old .h headers is a compatibility requirement and those features
(listed in Annex D, BTW) have been deprecated. Now, things that are
macros in C are still macros in C++, see 17.4.1.2/5. The C++ Standard
_allows_ their implementation as functions but doesn't *mandate* it.

V


Oh, okay. It's just that I had a look at some of those c-headers a while
ago, and I spotted tons of #undef's and macros replaced by inline
functions. That's why I thought assert would now be an inline function, too.

--
Matthias Kaeppler
Jul 23 '05 #6
Hi

Matthias Kaeppler wrote:
Oh, okay. It's just that I had a look at some of those c-headers a while
ago, and I spotted tons of #undef's and macros replaced by inline
functions. That's why I thought assert would now be an inline function,
too.


If you can think of some way how an inline function could be able to print
messages like "Assertion failed in line 7, file 'test.cc': 1 == 4" then I
think it will soon become an inline function. Until then it will stay a
macro.

Markus
Jul 23 '05 #7
Markus Moll wrote:
Hi

Matthias Kaeppler wrote:

Oh, okay. It's just that I had a look at some of those c-headers a while
ago, and I spotted tons of #undef's and macros replaced by inline
functions. That's why I thought assert would now be an inline function,
too.

If you can think of some way how an inline function could be able to print
messages like "Assertion failed in line 7, file 'test.cc': 1 == 4" then I
think it will soon become an inline function. Until then it will stay a
macro.

Markus


Good point :)

--
Matthias Kaeppler
Jul 23 '05 #8

"Matthias Kaeppler" <no****@digitalraid.com> wrote in message
news:d3*************@news.t-online.com...
Hi,

why can I use assert from <cassert> without resolving the std:: namespace?
E.g.:

#include <cassert>

int main()
{
assert(true); // shouldn't this be: std::assert(true) ?
}

This compiles. I thought in the <c****> headers the macros are undef'ed and
replaced in favor of inline functions which reside in the std namespace? In
this case my program shouldn't compile. I'm using g++ 3.3.5.


AFAIK, you don't have to use the std namespace for any of the <c*> headers.
This is true at least for cmath, cassert, and ctime.

- JFA1
Jul 23 '05 #9
James Aguilar wrote:
"Matthias Kaeppler" <no****@digitalraid.com> wrote in message
news:d3*************@news.t-online.com...
Hi,

why can I use assert from <cassert> without resolving the std:: namespace?
E.g.:

#include <cassert>

int main()
{
assert(true); // shouldn't this be: std::assert(true) ?
}

This compiles. I thought in the <c****> headers the macros are undef'ed and
replaced in favor of inline functions which reside in the std namespace? In
this case my program shouldn't compile. I'm using g++ 3.3.5.

AFAIK, you don't have to use the std namespace for any of the <c*> headers.
This is true at least for cmath, cassert, and ctime.


Actually you K incorrectly. All C library functions are declared inside
the 'std' namespace if you include the <c*> headers. If your compiler
doesn't do that and allows you to keep using unqualified names, it's
broken. Get a better one.

V
Jul 23 '05 #10
James Aguilar wrote:
AFAIK, you don't have to use the std namespace for any of the <c*> headers. This is true at least for cmath, cassert, and ctime.


That's the purpose of the <c*> headers - to improve the interface between
C++ and the legacy C Standard Library.

Naturally, many implementations compile a wide variety of sloppy
intermediate situations between the old styles and the new.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #11
Matthias Kaeppler wrote:

[ ... ]
Oh, okay. It's just that I had a look at some of those c-headers a
while ago, and I spotted tons of #undef's and macros replaced by
inline functions. That's why I thought assert would now be an
inline function, too.


assert expands to different things depending on whether NDEBUG is
defined at the point of expansion -- and you're allowed to #define and
#undef NDEBUG as you see fit throughout a translation unit. For
example:

#define NDEBUG 1
assert(x==1);
#undef NDEBUG
assert(y==2);

In this case, the first and second are required to expand differently
-- the first expands to something like '((void)0)', while the second
actually does an assertion.

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 23 '05 #12
Victor Bazarov wrote:

Actually you K incorrectly. All C library functions are declared inside
the 'std' namespace if you include the <c*> headers. If your compiler
doesn't do that and allows you to keep using unqualified names, it's
broken. Get a better one.


That's what the standard requires, but in practice it's unimplementable.
The problem is that the C++ standard effectively requires that the C
headers be rewritten to match C++'s rules, and that just won't fly. So
what you usually get is that the c* headers pull the C names into the
global namespace by including the C header, then hoist them into std
with using directives. There's an open defect report that would change
the standard to match reality: the c* headers give you names in std (and
maybe in the global namespace), the C headers give you names in the
global namespace (and maybe in std).

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #13
Victor Bazarov wrote:
Now, things that are
macros in C are still macros in C++, see 17.4.1.2/5. The C++ Standard
_allows_ their implementation as functions but doesn't *mandate* it.


It requires them to be macros. If they weren't, you wouldn't know
whether to write offsetof or std::offsetof. It also prohibits using
macros to mask functions, for the same reason (and you don't need those
macros in C++ because you can get the equivalent with inline).

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: stephan beal | last post by:
Good afternoon, C++ers, This weekend i came across a fairly project-neutral trick which can be used to map C++ class names to their human-readable equivalents (a-la QObject's className()...
11
by: Charles L | last post by:
I have read that the inclusion of <fstream.h> makes the inclusion of <iostream.h> unnecessary. Is this correct? Charles L
6
by: Karl Ebener | last post by:
Hi! I am currently using a string to hold data (can be strings as well as binary!). Now it occured to me, that the <string> might be unable to handle Null-Bytes. Is that so? Following...
20
by: Oliver S. | last post by:
I was often annoyed about the performance of std::basic-string because of complex memory-allocators working in the background to found the work of std::allocator<T>. Basically, the performance...
8
by: barcaroller | last post by:
I have a pointer to a memory block. Is there a way I can map a vector<Tto this memory block? I would like to take advantage of the powerful vector<T> member functions. Please note that I cannot...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.