Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

'assert': identifier not found - in Release mode

Posted on 2009-04-08
9
Medium Priority
?
2,716 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

885 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