Solved

'assert': identifier not found - in Release mode

Posted on 2009-04-08
9
2,459 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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 30 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 3

Assisted Solution

by:norsethomas
norsethomas earned 20 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now