strange boolean error!

Started by
6 comments, last by Driv3MeFar 17 years, 11 months ago
This have never happened to me before and for some reason I cant fix the problem. Language: C Compiler: VS 2005

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[], char *envp[]) {
	bool bActive = false;

	exit(0);
}
errors:

1>.\main.c(6) : error C2065: 'bool' : undeclared identifier
1>.\main.c(6) : error C2146: syntax error : missing ';' before identifier 'bActive'
1>.\main.c(6) : error C2065: 'bActive' : undeclared identifier
1>.\main.c(6) : error C2065: 'false' : undeclared identifier
Anyone have any clue as to why I can't use a simple boolen data type?
Advertisement
Most C compilers( implementing the C 89 standard ) don't have a bool data type : Link.
Thank you for the comment about C boolean. I just swear I've used boolean in C before on my compiler (or was I just dreamming). Another strange problem is happening with my for loop interator 'i', and the int variable 'path_amount'...

#include <stdio.h>#include <stdlib.h>#include <string.h>int main(int argc, char *argv[], char *envp[]) {	char **pCmdPath;	char *pHomeDir, *pCurrentDir;	char *result;	result = getenv("HOMEPATH");	pHomeDir = (char *)malloc(strlen(result));	strcpy(pHomeDir, result);	result = getenv("Path");		int path_amount = 1;	for(int i = 0; i < strlen(result); i++) {		if(result == ';')			path_amount++;	}		// Free Memory	free(result);	free(pHomeDir);	exit(0); // exit successful}


Errors:

1>.\main.c(16) : error C2143: syntax error : missing ';' before 'type'1>.\main.c(17) : error C2143: syntax error : missing ';' before 'type'1>.\main.c(17) : error C2143: syntax error : missing ';' before 'type'1>.\main.c(17) : error C2143: syntax error : missing ')' before 'type'1>.\main.c(17) : error C2143: syntax error : missing ';' before 'type'1>.\main.c(17) : error C2065: 'i' : undeclared identifier1>.\main.c(17) : warning C4552: '<' : operator has no effect; expected operator with side-effect1>.\main.c(17) : error C2059: syntax error : ')'1>.\main.c(17) : error C2143: syntax error : missing ';' before '{'1>.\main.c(19) : error C2065: 'path_amount' : undeclared identifier


Today is not a good day for I'm guess... (hahaha) = ]
Looks likethe compiler you are using wants all variables decalred at the top of the function.

I don't know, I don't use C too often but that is what I had to do when I was using VC 6 compiler for college (*shudders*).
Yeah that's what its wanting (yuck), I'm using Visual Studio 2005. I don't normally use C but my professor wants our class to use C instead of C++. I try reasoning with him but no luck. = /
typedef enum bool { false, true };

declared in some header you create (e.g. "bool.h") should sort you out.

EDIT: The poster above was correct also in that in C you must declare all variables in a scope block before you use any expressions... you can get around this by using a new scope block {} e.g.

void funcenstein(void){    int x;        x = 0; /* this is an expression */    {        int y; /* this would be an error without introducing a new scope block in C */        y = x;    }}


[Edited by - Paradigm Shifter on May 5, 2006 6:23:30 PM]
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
>typedef enum bool { false, true };

Which would be the same as
typedef enum bool { false=0, true=1 };

Although actually false = 0 and true is everything else.

So (assuming there are no built-in types in your compiler) it's
better to define true as !false...

visit my website at www.kalmiya.com
edit: should have read earlier posts

This topic is closed to new replies.

Advertisement