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

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

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

Post 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
Last edited by MadPumpkin on Mon Dec 19, 2011 7:09 am, edited 1 time in total.
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
Aleios
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 78
Joined: Mon Feb 21, 2011 2:55 am
Current Project: Aleios Engine
Favorite Gaming Platforms: PC, Dreamcast
Programming Language of Choice: C++
Location: Melbourne, Australia

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

Post 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.
Image
User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

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

Post 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.
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
Post Reply