|
List Info
Thread: error C2065: 'true' : undeclared identifier
|
|
| error C2065: 'true' : undeclared
identifier |
  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 |
  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>
// MFC core
and standard components
#include
<afxext.h>
// MFC
extensions
#include
<afxhtml.h>
// MFC html
support
#ifndef
_AFX_NO_OLE_SUPPORT
#include
<afxole.h>
// MFC OLE
classes
#include
<afxodlgs.h>
// MFC OLE
dialog classes
#include
<afxdisp.h>
// MFC OLE
automation classes
#endif
//
_AFX_NO_OLE_SUPPORT
#ifndef
_AFX_NO_DB_SUPPORT
#include
<afxdb.h>
// MFC ODBC
database classes
#endif
//
_AFX_NO_DB_SUPPORT
#ifndef
_AFX_NO_DAO_SUPPORT
#include
<afxdao.h>
// MFC DAO
database classes
#endif
//
_AFX_NO_DAO_SUPPORT
#ifndef
_AFX_NO_AFXCMN_SUPPORT
#include
<afxcmn.h>
// MFC
support for Windows 95 Common Controls
#endif
//
_AFX_NO_AFXCMN_SUPPORT
Phil Daley <
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 |
  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 |

|
2007-03-06 22:01:37 |
|
Nice catch, Ehsan -- so mystifying at first, so obvious when solved... 
-cleo
On 3/5/07, Ehsan Akhgari < ehsan beginthread.com">
ehsan beginthread.com> wrote: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 'int39; 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.exe?SHOWTPL=COPYRIGHT&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]
|
|