Solved

'assert': identifier not found - in Release mode

Posted on 2009-04-08
9
2,373 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
Comment Utility
>>>> 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
Comment Utility
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
Comment Utility
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
 
LVL 3

Assisted Solution

by:norsethomas
norsethomas earned 20 total points
Comment Utility

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Expert Comment

by:mayank13
Comment Utility
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
Comment Utility
>>>> 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
Comment Utility

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
Comment Utility
norsethomas, thanks.
0
 

Author Closing Comment

by:AlexInAustralia
Comment Utility
Thank you guys for your help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 142
sameEnds challenge 3 105
ShiftLeft challenge 21 64
basic hardware to learn oop advanced design patterns 3 71
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

728 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

10 Experts available now in Live!

Get 1:1 Help Now