Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

'assert': identifier not found - in Release mode

Posted on 2009-04-08
9
Medium Priority
?
2,659 Views
Last Modified: 2013-12-14
I've got some cod which compiles fine in debug mode but gives the following error when compiling in release mode:
'assert': identifier not found

The simple fix is to put a #include <cassert> in the file where the problem occurs.
However, I thought assert statements are ignored in release mode, so technically I shouldn't be getting this problem.

I'm using Visual Studio 2005 Pro with SP1 running on WinXP with SP3. The application is a C++ solution and uses MFC.
0
Comment
Question by:AlexInAustralia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 120 total points
ID: 24104989
>>>> I thought assert statements are ignored in release mode

That is on runtime only cause the assert function was implement  like

void assert(BOOL b)
{
#ifdef _DEBUG
       user_break();
#endif
}

But for the compiler the assert function must be available even in release mode.

0
 

Expert Comment

by:mayank13
ID: 24105759
you have to declare assert header file.

At runtime, assert function not called but, at compile time compiler needs definition of assert() function.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24105827
mayank13, you didn't tell anyting what wasn't already told.

Your first statement repeats what the asker has said in the initial question.

The second repeats the last sentence of my comment.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 3

Assisted Solution

by:norsethomas
norsethomas earned 80 total points
ID: 24106217

I'm sorry, mayank13 and itsmeandnobodyelse. The point with the inclusion of the header file is correct. However, "assert" is not a function, but a macro. This means, there is no trace of an assert in codes that were compiled with NDEBUG and that had assert.h included (or cassert)

If the header file is not included, it depends on the compiler how to proceed with the undefined identifier "assert". If it is a true C++ compiler, it should claim that "assert" is undefined (and stop). If it is a C compiler, the identifier "assert" is supposed to be external to the current compilation unit. From this point of view, the microsoft compiler is right.

norsethomas
0
 

Expert Comment

by:mayank13
ID: 24106384
itsmeandnobodyelse: ... sorry for redundant answer, actually i didn't read comments i just read the problem and gave comments. I'll keep in mind for future.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24107338
>>>> However, "assert" is not a function, but a macro.
don't think that it is necessarily a macro.

And the error message is the same no matter whether it is a function or a macro.  
0
 
LVL 3

Expert Comment

by:norsethomas
ID: 24113447

itsmeandnobodyelse,

from the C standard, which defines assert.h

7.2 Diagnostics
1 The header  defines the assert macro and refers to another macro,
NDEBUG which is not defined by . If NDEBUG is defined as a macro name at the
point in the source file where  is included, the assert macro is defined
simply as
#define assert(ignore) ((void)0)
The assert macro is redefined


norsemanna
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24113704
norsethomas, thanks.
0
 

Author Closing Comment

by:AlexInAustralia
ID: 31568360
Thank you guys for your help
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question