Sign in to follow this  

strange boolean error!

This topic is 4273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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[i] == ';')
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 identifier
1>.\main.c(17) : warning C4552: '<' : operator has no effect; expected operator with side-effect
1>.\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) = ]

Share this post


Link to post
Share on other sites
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*).

Share this post


Link to post
Share on other sites
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. = /

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
>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...

Share this post


Link to post
Share on other sites
Sign in to follow this