List Info

Thread: error C2065: 'true' : undeclared identifier




error C2065: 'true' : undeclared identifier
country flaguser name
United States
2007-03-05 11:19:17
I thought I knew c++ pretty well, but I'm beginning to have some serious doubts.

I found some 'c' code I wanted to try out. (It was written for Linux, but that's not relevant.) In VS2005, I created a new console app project, and added the files I had downloaded. With a few minor tweaks, the program builds and runs. One place in the code, an 'int' variable was used for a boolean concept. I changed the variable to a bool, and fixed all references to it. That's about when I must have lost my mind. I rebuilt the project, and the line: ;

    bool   ; bWait = true;

produced the following errors:

    Error ;   1    error C2061: syntax error : identifier 'bWait'            c:...main.c    30
    Error ;   2    error C2059: syntax error : ';'                    c:...main.c    30
    Error ;   3    error C2513: '/*global*/ ' : no variable declared before '='    c:...main.c    30
    Error ;   4    error C2065: 'true' : undeclared identifier  ;          c:...main.c    30

I double-checked my properties to ensure I was building as a c++ project.

What do you do when your c++ compiler doesn't recognize 'true'? (or 'false', or 'bool'?)

Somebody, please, just shoot me!

Jeff Nygren

 


Now that's room service! Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel
to find your fit. -------------------------------------------------------------------------- The MSVC list is hosted on a Windows NT(TM) machine running L-Soft international's LISTSERV(R) software. For subscription/signoff info and archives, see http://peach.ease.lsoft.com/archives/msvc.html .
COPYRIGHT INFO:
http://peach.ease.lsoft.com/scripts/wa.exe?SHOWTPL=COPYRIGHT&L=MSVC
Re: error C2065: 'true' : undeclared identifier
country flaguser name
United States
2007-03-05 12:07:10
At 3/5/2007 12:19 PM, J Nygren wrote:
 
    bool    bWait = true;

produced the following errors:

It sounds like you didn't include the standard Microsoft header files.

The stdafx.h should have something like:

// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//  ;    are changed infrequently
//

#ifndef WINVER
#define WINVER 0x0500
#endif

#define
VC_EXTRALEAN        // Exclude rarely-used stuff from Windows headers

#include <afxwin.h> &nbsp; &nbsp; &nbsp; &nbsp; // MFC core and standard components
#include <afxext.h> &nbsp; &nbsp; &nbsp; &nbsp; // MFC extensions
#include <afxhtml.h> &nbsp; &nbsp; &nbsp;  // MFC html support

#ifndef _AFX_NO_OLE_SUPPORT
#include <afxole.h> &nbsp; &nbsp; &nbsp; &nbsp; // MFC OLE classes
#include <afxodlgs.h> &nbsp; &nbsp; &nbsp; // MFC OLE dialog classes
#include <afxdisp.h> &nbsp; &nbsp; &nbsp;  // MFC OLE automation classes
#endif // _AFX_NO_OLE_SUPPORT


#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h> &nbsp; &nbsp; &nbsp; &nbsp;  // MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT

#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h> &nbsp; &nbsp; &nbsp; &nbsp; // MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT

#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> &nbsp; &nbsp; &nbsp; &nbsp; // MFC support for Windows 95 Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT


Phil Daley ; &nbsp; &nbsp; &nbsp; &nbsp; < AutoDesk >
http://www.conknet.com/~p_daley


-------------------------------------------------------------------------- The MSVC list is hosted on a Windows NT(TM) machine running L-Soft international's LISTSERV(R) software. For subscription/signoff info and archives, see http://peach.ease.lsoft.com/archives/msvc.html .
COPYRIGHT INFO:
http://peach.ease.lsoft.com/scripts/wa.exe?SHOWTPL=COPYRIGHT&L=MSVC
Re: error C2065: 'true' : undeclared identifier
country flaguser name
Iran, Islamic Republic of
2007-03-05 21:42:04
J Nygren wrote:
> I thought I knew c++ pretty well, but I'm beginning to
have some serious 
> doubts.
> 
> I found some 'c' code I wanted to try out. (It was
written for Linux, 
> but that's not relevant.) In VS2005, I created a new
console app 
> project, and added the files I had downloaded. With a
few minor tweaks, 
> the program builds and runs. One place in the code, an
'int' variable 
> was used for a boolean concept. I changed the variable
to a bool, and 
> fixed all references to it. That's about when I must
have lost my mind. 
> I rebuilt the project, and the line: 
> 
>     bool    bWait = true;
> 
> produced the following errors:
> 
>     Error    1    error C2061: syntax error :
identifier 'bWait'        
>     c:...main.c    30
>     Error    2    error C2059: syntax error : ';'      
             
> c:...main.c    30
>     Error    3    error C2513: '/*global*/ ' : no
variable declared 
> before '='    c:...main.c    30
>     Error    4    error C2065: 'true' : undeclared
identifier            
> c:...main.c    30
> 
> I double-checked my properties to ensure I was building
as a c++ project.
> 
> What do you do when your c++ compiler doesn't recognize
'true'? (or 
> 'false', or 'bool'?)

It's not the C++ compiler, it's the C compiler.  See, C
doesn't have the 
bool type, and it doesn't also have the true and false
keywords. 
Changing the file extension to .cpp (to invoke the C++
compiler on it) 
will probably solve this issue (unless there's some C code
elsewhere 
which is not valid C++.)  If you need to keep it a C file,
then switch 
bool with traditional int type used for Boolean values.

Ehsan

------------------------------------------------------------
--------------
The MSVC list is hosted on a Windows NT(TM) machine running
L-Soft
international's LISTSERV(R) software.  For
subscription/signoff info
and archives, see http:/
/peach.ease.lsoft.com/archives/msvc.html .
                             COPYRIGHT INFO:
http://peach.ease.lsoft.com/scripts/wa.ex
e?SHOWTPL=COPYRIGHT&L=MSVC

Re: error C2065: 'true' : undeclared identifier
user name
2007-03-06 22:01:37
Nice catch, Ehsan -- so mystifying at first, so obvious when solved...

-cleo

On 3/5/07, Ehsan Akhgari < ehsanbeginthread.com"> ehsanbeginthread.com> wrote:
J Nygren wrote:
>; I thought I knew c++ pretty well, but I'm beginning to have some serious
> doubts.
&gt;
> I found some 'c'; code I wanted to try out. (It was written for Linux,
>; but that's not relevant.) In VS2005, I created a new console app
> project, and added the files I had downloaded. With a few minor tweaks,
> the program builds and runs. One place in the code, an 'int&#39; variable
&gt; was used for a boolean concept. I changed the variable to a bool, and
> fixed all references to it. That's about when I must have lost my mind.
&gt; I rebuilt the project, and the line:
>
  ;  bool   ; bWait = true;
>
> produced the following errors:
&gt;
>&nbsp; &nbsp;  Error ; &nbsp; 1&nbsp; &nbsp; error C2061: syntax error : identifier 'bWait'
>; &nbsp; &nbsp; c:...main.c &nbsp; &nbsp;30
>&nbsp;   ; Error ; &nbsp; 2&nbsp; &nbsp; error C2059: syntax error : ';';
> c:...main.c &nbsp; &nbsp;30
>&nbsp;   ; Error ; &nbsp; 3&nbsp; &nbsp; error C2513: '/*global*/ ' : no variable declared
&gt; before '='; &nbsp; &nbsp;c:...main.c &nbsp; &nbsp;30
&gt; &nbsp; &nbsp; Error ; &nbsp; 4&nbsp; &nbsp; error C2065: 'true&#39; : undeclared identifier
> c:...main.c &nbsp; &nbsp;30
>
> I double-checked my properties to ensure I was building as a c++ project.
&gt;
> What do you do when your c++ compiler doesn't recognize 'true&#39;? (or
> 'false', or 'bool&#39;?)

It&#39;s not the C++ compiler, it's the C compiler.&nbsp; See, C doesn't have the
bool type, and it doesn't also have the true and false keywords.
Changing the file extension to .cpp (to invoke the C++ compiler on it)
will probably solve this issue (unless there's some C code elsewhere
which is not valid C++.) ; If you need to keep it a C file, then switch
bool with traditional int type used for Boolean values.

Ehsan

--------------------------------------------------------------------------
The MSVC list is hosted on a Windows NT(TM) machine running L-Soft
international&#39;s LISTSERV(R) software.&nbsp; For subscription/signoff info
and archives, see http://peach.ease.lsoft.com/archives/msvc.html .
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   COPYRIGHT INFO:
http://peach.ease.lsoft.com/scripts/wa.exe?SHOWTPL=COPYRIGHT&amp;L=MSVC

-------------------------------------------------------------------------- The MSVC list is hosted on a Windows NT(TM) machine running L-Soft international's LISTSERV(R) software. For subscription/signoff info and archives, see http://peach.ease.lsoft.com/archives/msvc.html .
COPYRIGHT INFO:
http://peach.ease.lsoft.com/scripts/wa.exe?SHOWTPL=COPYRIGHT&L=MSVC
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )