Solved

'assert': identifier not found - in Release mode

Posted on 2009-04-08
9
2,491 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change local server setting in php 6 96
wordmultiple challenge 12 142
eclipse package explorer vs project explorer view 2 182
FMX TEdit KeyUp handler detecting  "enter" key 4 14
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

830 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