Page 1 of 1

[SOLVED]error: a label can only be part of a statement...

Posted: Mon Dec 19, 2011 5:28 am
by MadPumpkin
I'm writing a brainfuck interpreter in C, and I'm having issues with some code. I'm not used to gcc, but I haven't had a programming problem (that I couldn't solve) in a long time, and this is different than the code I normally write.
A ',' in brainfuck is supposed to take a single character input. So:

Code: Select all

// This is just what ptr is
static char *ptr;
// Here's the code causing error
case ',':
	ptr*=getchar();
	break;
This is causing an error:

Code: Select all

error: a label can only be part of a statement and a declaration is not a statement 
I really have no idea why

Re: error: a label can only be part of a statement...

Posted: Mon Dec 19, 2011 6:27 am
by Aleios
Is case ',': in a switch statement? if not, then there is your problem.
if static char *ptr; is inside a switch statement but not under a case label, then that may be your issue.

Re: [SOLVED]error: a label can only be part of a statement..

Posted: Mon Dec 19, 2011 7:10 am
by MadPumpkin
Yea it was in a switch, I'm just so used to writing this shit in code that I forget it when I talk about what the issue is, expecting that it's assumed :P. Sorry about that. But I figured out what the problem was, it wasn't even with this part of the code, it was with something I commented out at the same time, which led my belief that it was the issue. I simply forgot { and } inside of a different case, when I was declaring a variable in that case.

EDIT: Stupid mistakes ftw.