473,545 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

assert

Hello everyone,
I saw a couple of form of assert in code on Windows,

1. ASSERT;
2. assert;
3. _ASSERT;
4. _assert.

Which one is the most correct to use? I saw people always define this to
that, and I want to find the root one which is defined by Windows.

I also saw people manually define assert to NULL if macro DEBUG or _DEBUG is
not defined, is that necessary?

I feel assert is in a mess and I want to find a clear and unified way for
this item.
thanks in advance,
George
Oct 22 '07 #1
12 1901
I created and use this class, you might find it useful. It contains some
useful methods, pretty easy to figure out from their names. Note that I use
'assert' to answer your question:

#include 'assert.h'

#define MY_DEBUG (true)

ref class My_Debug
{
public:

static void Assert( bool condition )
{
Assert( condition, "<no text>" ) ;
}

static void Show( String^ comment )
{
Console::WriteL ine( comment ) ;
}

static void Assert( bool condition, String^ info )
{
if ( condition ) { return ; }
Console::WriteL ine() ;
Console::WriteL ine( info ) ;
Console::WriteL ine() ;
assert(!MY_DEBU G) ; // when debug is on then assert false
}

static void Deny( bool condition )
{
Assert( !condition ) ;
}

static void Deny( bool condition, String^ info )
{
Assert( !condition, info ) ;
}

static void Abort( String^ info )
{
Assert( false, info ) ;
}

static void Abort()
{
Abort( "*abort*" ) ;
}
} ;

// [==Peter==]

"George" <Ge****@discuss ions.microsoft. comwrote in message
news:C1******** *************** ***********@mic rosoft.com...
Hello everyone,
I saw a couple of form of assert in code on Windows,

1. ASSERT;
2. assert;
3. _ASSERT;
4. _assert.

Which one is the most correct to use? I saw people always define this to
that, and I want to find the root one which is defined by Windows.

I also saw people manually define assert to NULL if macro DEBUG or _DEBUG
is
not defined, is that necessary?

I feel assert is in a mess and I want to find a clear and unified way for
this item.
thanks in advance,
George

Oct 22 '07 #2
Generally I prefer to use 'assert' because is standard, but in MFC/ATL I use
ASSERT because the debugger stop on the offending line (this is not true for
assert). I've just used _ASSERT on a few occasions (when I used CRT debugging
functions to find a leak).

Be aware that:

- assert depends of NDEBUG macro.
- ASSERT and _ASSERT depend of _DEBUG macro.
Regards

--
Cholo Lennon
Bs.As.
ARG
"George" <Ge****@discuss ions.microsoft. comwrote in message
news:C1******** *************** ***********@mic rosoft.com...
Hello everyone,
I saw a couple of form of assert in code on Windows,

1. ASSERT;
2. assert;
3. _ASSERT;
4. _assert.

Which one is the most correct to use? I saw people always define this to
that, and I want to find the root one which is defined by Windows.

I also saw people manually define assert to NULL if macro DEBUG or _DEBUG is
not defined, is that necessary?

I feel assert is in a mess and I want to find a clear and unified way for
this item.
thanks in advance,
George

Oct 22 '07 #3
Thanks Peter,
The class is very useful. I have a further question, why do you add ref
before class?
regards,
George

"Peter Oliphant" wrote:
I created and use this class, you might find it useful. It contains some
useful methods, pretty easy to figure out from their names. Note that I use
'assert' to answer your question:

#include 'assert.h'

#define MY_DEBUG (true)

ref class My_Debug
{
public:

static void Assert( bool condition )
{
Assert( condition, "<no text>" ) ;
}

static void Show( String^ comment )
{
Console::WriteL ine( comment ) ;
}

static void Assert( bool condition, String^ info )
{
if ( condition ) { return ; }
Console::WriteL ine() ;
Console::WriteL ine( info ) ;
Console::WriteL ine() ;
assert(!MY_DEBU G) ; // when debug is on then assert false
}

static void Deny( bool condition )
{
Assert( !condition ) ;
}

static void Deny( bool condition, String^ info )
{
Assert( !condition, info ) ;
}

static void Abort( String^ info )
{
Assert( false, info ) ;
}

static void Abort()
{
Abort( "*abort*" ) ;
}
} ;

// [==Peter==]

"George" <Ge****@discuss ions.microsoft. comwrote in message
news:C1******** *************** ***********@mic rosoft.com...
Hello everyone,
I saw a couple of form of assert in code on Windows,

1. ASSERT;
2. assert;
3. _ASSERT;
4. _assert.

Which one is the most correct to use? I saw people always define this to
that, and I want to find the root one which is defined by Windows.

I also saw people manually define assert to NULL if macro DEBUG or _DEBUG
is
not defined, is that necessary?

I feel assert is in a mess and I want to find a clear and unified way for
this item.
thanks in advance,
George


Oct 23 '07 #4
Thanks Cholo,
What do you mean *because the debugger stop on the offending line*? Debugger
will stop even if the value is true?
regards,
George

"Cholo Lennon" wrote:
Generally I prefer to use 'assert' because is standard, but in MFC/ATL I use
ASSERT because the debugger stop on the offending line (this is not true for
assert). I've just used _ASSERT on a few occasions (when I used CRT debugging
functions to find a leak).

Be aware that:

- assert depends of NDEBUG macro.
- ASSERT and _ASSERT depend of _DEBUG macro.
Regards

--
Cholo Lennon
Bs.As.
ARG
"George" <Ge****@discuss ions.microsoft. comwrote in message
news:C1******** *************** ***********@mic rosoft.com...
Hello everyone,
I saw a couple of form of assert in code on Windows,

1. ASSERT;
2. assert;
3. _ASSERT;
4. _assert.

Which one is the most correct to use? I saw people always define this to
that, and I want to find the root one which is defined by Windows.

I also saw people manually define assert to NULL if macro DEBUG or _DEBUG is
not defined, is that necessary?

I feel assert is in a mess and I want to find a clear and unified way for
this item.
thanks in advance,
George


Oct 23 '07 #5
No, only when the value is false.

I'm sorry, when I said "...debugge r stops on...", I should have said
"...debugge r breaks on...".

Try to debug a program using assert(false) and ASSERT(false) to see what
happens. In the 1st case the debugger break into an internal function. In the
2nd case it just break on the ASSERT line.

Regards

--
Cholo Lennon
Bs.As.
ARG
"George" <Ge****@discuss ions.microsoft. comwrote in message
news:46******** *************** ***********@mic rosoft.com...
Thanks Cholo,
What do you mean *because the debugger stop on the offending line*? Debugger
will stop even if the value is true?
regards,
George

"Cholo Lennon" wrote:
Generally I prefer to use 'assert' because is standard, but in MFC/ATL I use
ASSERT because the debugger stop on the offending line (this is not true for
assert). I've just used _ASSERT on a few occasions (when I used CRT
debugging
functions to find a leak).

Be aware that:

- assert depends of NDEBUG macro.
- ASSERT and _ASSERT depend of _DEBUG macro.
Regards

--
Cholo Lennon
Bs.As.
ARG
"George" <Ge****@discuss ions.microsoft. comwrote in message
news:C1******** *************** ***********@mic rosoft.com...
Hello everyone,
>
>
I saw a couple of form of assert in code on Windows,
>
1. ASSERT;
2. assert;
3. _ASSERT;
4. _assert.
>
Which one is the most correct to use? I saw people always define this to
that, and I want to find the root one which is defined by Windows.
>
I also saw people manually define assert to NULL if macro DEBUG or _DEBUG
is
not defined, is that necessary?
>
I feel assert is in a mess and I want to find a clear and unified way for
this item.
>
>
thanks in advance,
George

Oct 23 '07 #6
Thanks Cholo,
It is my mistake to misunderstand your points. Now I am clear now.
regards,
George

"Cholo Lennon" wrote:
No, only when the value is false.

I'm sorry, when I said "...debugge r stops on...", I should have said
"...debugge r breaks on...".

Try to debug a program using assert(false) and ASSERT(false) to see what
happens. In the 1st case the debugger break into an internal function. In the
2nd case it just break on the ASSERT line.

Regards

--
Cholo Lennon
Bs.As.
ARG
"George" <Ge****@discuss ions.microsoft. comwrote in message
news:46******** *************** ***********@mic rosoft.com...
Thanks Cholo,
What do you mean *because the debugger stop on the offending line*? Debugger
will stop even if the value is true?
regards,
George

"Cholo Lennon" wrote:
Generally I prefer to use 'assert' because is standard, but in MFC/ATL I use
ASSERT because the debugger stop on the offending line (this is not true for
assert). I've just used _ASSERT on a few occasions (when I used CRT
debugging
functions to find a leak).
>
Be aware that:
>
- assert depends of NDEBUG macro.
- ASSERT and _ASSERT depend of _DEBUG macro.
>
>
Regards
>
--
Cholo Lennon
Bs.As.
ARG
>
>
"George" <Ge****@discuss ions.microsoft. comwrote in message
news:C1******** *************** ***********@mic rosoft.com...
Hello everyone,


I saw a couple of form of assert in code on Windows,

1. ASSERT;
2. assert;
3. _ASSERT;
4. _assert.

Which one is the most correct to use? I saw people always define this to
that, and I want to find the root one which is defined by Windows.

I also saw people manually define assert to NULL if macro DEBUG or _DEBUG
is
not defined, is that necessary?

I feel assert is in a mess and I want to find a clear and unified way for
this item.


thanks in advance,
George
>
>
>


Oct 23 '07 #7

"George" <Ge****@discuss ions.microsoft. comwrote in message
news:F7******** *************** ***********@mic rosoft.com...
Thanks Peter,
The class is very useful. I have a further question, why do you add ref
before class?
That makes it a .NET class, visible from other .NET languages.

>

regards,
George

"Peter Oliphant" wrote:
>I created and use this class, you might find it useful. It contains some
useful methods, pretty easy to figure out from their names. Note that I
use
'assert' to answer your question:

#include 'assert.h'

#define MY_DEBUG (true)

ref class My_Debug
{
public:

static void Assert( bool condition )
{
Assert( condition, "<no text>" ) ;
}

static void Show( String^ comment )
{
Console::WriteL ine( comment ) ;
}

static void Assert( bool condition, String^ info )
{
if ( condition ) { return ; }
Console::WriteL ine() ;
Console::WriteL ine( info ) ;
Console::WriteL ine() ;
assert(!MY_DEBU G) ; // when debug is on then assert false
}

static void Deny( bool condition )
{
Assert( !condition ) ;
}

static void Deny( bool condition, String^ info )
{
Assert( !condition, info ) ;
}

static void Abort( String^ info )
{
Assert( false, info ) ;
}

static void Abort()
{
Abort( "*abort*" ) ;
}
} ;

// [==Peter==]

"George" <Ge****@discuss ions.microsoft. comwrote in message
news:C1******* *************** ************@mi crosoft.com...
Hello everyone,
I saw a couple of form of assert in code on Windows,

1. ASSERT;
2. assert;
3. _ASSERT;
4. _assert.

Which one is the most correct to use? I saw people always define this
to
that, and I want to find the root one which is defined by Windows.

I also saw people manually define assert to NULL if macro DEBUG or
_DEBUG
is
not defined, is that necessary?

I feel assert is in a mess and I want to find a clear and unified way
for
this item.
thanks in advance,
George



Oct 23 '07 #8

"Peter Oliphant" <po*******@roun dtripllc.comwro te in message
news:u5******** ******@TK2MSFTN GP04.phx.gbl...
>I have a further question, why do you add ref before class?

There are two basic kinds of classes (or structs, since structs are now
just classes that are internally default public): reference classes and
value classes.
Everything you wrote is true about .NET types. The C++/CLI compiler
supports .NET types of both varieties (actually four varieties, if you
include interfaces and enums), and also standard C++ classes, PODs, and
enums. So for the C++/CLI programmer, there are many different kinds.
Oct 23 '07 #9
Thanks Ben,
regards,
George

"Ben Voigt [C++ MVP]" wrote:
>
"George" <Ge****@discuss ions.microsoft. comwrote in message
news:F7******** *************** ***********@mic rosoft.com...
Thanks Peter,
The class is very useful. I have a further question, why do you add ref
before class?

That makes it a .NET class, visible from other .NET languages.



regards,
George

"Peter Oliphant" wrote:
I created and use this class, you might find it useful. It contains some
useful methods, pretty easy to figure out from their names. Note that I
use
'assert' to answer your question:

#include 'assert.h'

#define MY_DEBUG (true)

ref class My_Debug
{
public:

static void Assert( bool condition )
{
Assert( condition, "<no text>" ) ;
}

static void Show( String^ comment )
{
Console::WriteL ine( comment ) ;
}

static void Assert( bool condition, String^ info )
{
if ( condition ) { return ; }
Console::WriteL ine() ;
Console::WriteL ine( info ) ;
Console::WriteL ine() ;
assert(!MY_DEBU G) ; // when debug is on then assert false
}

static void Deny( bool condition )
{
Assert( !condition ) ;
}

static void Deny( bool condition, String^ info )
{
Assert( !condition, info ) ;
}

static void Abort( String^ info )
{
Assert( false, info ) ;
}

static void Abort()
{
Abort( "*abort*" ) ;
}
} ;

// [==Peter==]

"George" <Ge****@discuss ions.microsoft. comwrote in message
news:C1******** *************** ***********@mic rosoft.com...
Hello everyone,
I saw a couple of form of assert in code on Windows,

1. ASSERT;
2. assert;
3. _ASSERT;
4. _assert.

Which one is the most correct to use? I saw people always define this
to
that, and I want to find the root one which is defined by Windows.

I also saw people manually define assert to NULL if macro DEBUG or
_DEBUG
is
not defined, is that necessary?

I feel assert is in a mess and I want to find a clear and unified way
for
this item.
thanks in advance,
George


Oct 24 '07 #10

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

Similar topics

28
3543
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a very early draft for a new "assert" syntax: This was inspired in Ruby's assert syntax. I'm not familiar with Ruby at all, so the chances are that...
3
3951
by: Thomas Guettler | last post by:
Hi, Python 2.3.3 (#1, Feb 5 2005, 16:22:10) on linux2 >>> assert 0, "foo" Traceback (most recent call last): File "<stdin>", line 1, in ? AssertionError: foo >>> assert(0, "foo") >>>
27
3809
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get failed assertions for assertions that at first thought ought to hold, but that's not important.) At the end is a full program containing the above...
5
3152
by: Alex Vinokur | last post by:
Here are two programs. --- foo1.c --- #include <assert.h> #define FOO 10 int main() { assert (15 < FOO); return 0; }
47
3064
by: Rob Thorpe | last post by:
In general, is it considered bad practice to use asserts in production code? What about writing a macro that does the same as assert but continues to work regardless of the state of NDEBUG? I can see that it would be poor style to use it for commonly encountered errors, but what about truly exceptional errors that would rarely if ever be...
28
5693
by: lovecreatesbeauty | last post by:
Besides printing out for example " a.out: p113.c:8: main: Assertion `0' failed. Aborted " and a switch option NDEBUG, what other benefits does assert() provide in any scope of designing, debugging/coding and/or testing? Do you prefer the if statement of the language to the assert MACRO of the precompiler?
13
9398
by: priyanka | last post by:
Hi there, Can anyone show me how the assert() function works ? I need to develop my own assert() function instead of using the one defined in the assert.h file. It would be great if anyone could show me the actual source code of assert() function in assert.h header file. I need to write the assert function that prints out error message...
30
2148
by: Tomás Ó hÉilidhe | last post by:
In C89, do we have to pass an int as an argument to assert? I've got code at the moment that does an assertion on pointer, e.g.: assert(p); , but I'm wondering if I should change that to: assert(0 != p);
9
21452
by: pereges | last post by:
Ok, so once I'm done debugging my code(split across multiple modules) using the assert macro, I would want to switch off all the assert macros ued in the program. Does this mean I have to include: #define NDEBUG in every .c where I used assert or defining it one file would turn off all assert macros in every file ?
0
7478
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7668
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7923
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7437
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.