PDA

View Full Version : C error


meleader2
10-03-2005, 05:30 PM
../userprog/exception.cc: In function `char* UserToSystem(int, int, int)':
../userprog/exception.cc:107: parse error before `)' token
../userprog/exception.cc:107: parse error before `)' token
../userprog/exception.cc:129: parse error before `)' token
../userprog/exception.cc: In function `int SystemToUser(int, int, int, char*)':
../userprog/exception.cc:145: parse error before `)' token
../userprog/exception.cc:145: parse error before `)' token
../userprog/exception.cc:165: parse error before `)' token
../userprog/exception.cc:170: parse error before `)' token



oddly enough the line of code is:

if((numbytes<0) && ((charmode!=M_ASCII) || (charmode!=M_BINARY)))

i doubt i'll get any useful replies but my TA is taking forever so i thought hell i'll give this a whirl. numbytes, charmode is defined in the function declaration and M_ASCII/M_BINARY are #define b4 class starts.

dtbog
10-03-2005, 05:31 PM
it looks like the error comes before this line.

diebitter
10-03-2005, 05:32 PM
Yeah, I'm thinking C error, but not in the same way as you, I reckon.

meleader2
10-03-2005, 05:34 PM
[ QUOTE ]
it looks like the error comes before this line.

[/ QUOTE ]


i thought so too, as is usual with these compilers, but everything before it (4 lines) is just declarations of variables...no ( ) whatsoever. and then the function header...this project is due in 5 days. i'm toast.

dtbog
10-03-2005, 05:37 PM
where are these functions (e.g. UserToSystem) actually being called? look at those lines.

stinkypete
10-03-2005, 05:37 PM
the error isn't where you think it is. you'd have to post a whole lot more than this for us to tell you. it's probably something that seems totally unrelated to the error messages. like a missing semi-colon at the end of a line. or something.

meleader2
10-03-2005, 05:39 PM
[ QUOTE ]
the error isn't where you think it is. you'd have to post a whole lot more than this for us to tell you. it's probably something that seems totally unrelated to the error messages. like a missing semi-colon at the end of a line. or something.

[/ QUOTE ]

i'm thinking "or something". i don't think a missing semi colon will be missed by the compiler

meleader2
10-03-2005, 05:39 PM
[ QUOTE ]
where are these functions (e.g. UserToSystem) actually being called? look at those lines.

[/ QUOTE ]


it isn't exactly being called yet. i'm using gcc's gmake command...so i'm just linking right now...

dtbog
10-03-2005, 05:39 PM
[ QUOTE ]

i'm thinking "or something". i don't think a missing semi colon will be missed by the compiler

[/ QUOTE ]

you are mistaken. /images/graemlins/smile.gif

i've definitely seen it before

asofel
10-03-2005, 05:40 PM
cut back on the function until its a small amount of text that compiles. add in lines progressively and try to narrow down where the error is...think do this is a binary search type manner and it shouldn't take too long...

MonkeeMan
10-03-2005, 05:41 PM
I'm guessing a missing "}".

meleader2
10-03-2005, 05:46 PM
you know looking at it, it's happening only on M_ASCII and M_BINARY my lines for those are

#define M_ASCII
#define M_BINARY

i don't have any values for it. now i gotta figure out what the hell values i should give it.

OOT > TA's and professors combined.

asofel
10-03-2005, 05:52 PM
[ QUOTE ]
you know looking at it, it's happening only on M_ASCII and M_BINARY my lines for those are

#define M_ASCII YSSCKY
#define M_BINARY SIIHP

i don't have any values for it. now i gotta figure out what the hell values i should give it.

OOT > TA's and professors combined.

[/ QUOTE ]

if only i could have known of OOT before I graduated...coding would have been a lot more fun.

SL__72
10-03-2005, 05:59 PM
Yeah... I could have come up with better names then "blah" "blah1" "asdf" etc. for my random variables...

jba
10-03-2005, 06:01 PM
i dunno how those should be defined but

if((numbytes<0) && ((charmode!=M_ASCII) || (charmode!=M_BINARY)))

is the same as

if((numbytes<0))

if M_ASCII != M_BINARY

which doesn't seem right

meleader2
10-03-2005, 06:06 PM
[ QUOTE ]
Yeah... I could have come up with better names then "blah" "blah1" "asdf" etc. for my random variables...

[/ QUOTE ]

meleader2
10-03-2005, 06:08 PM
[ QUOTE ]
i dunno how those should be defined but

if((numbytes<0) && ((charmode!=M_ASCII) || (charmode!=M_BINARY)))

is the same as

if((numbytes<0))

if M_ASCII != M_BINARY

which doesn't seem right

[/ QUOTE ]


haha that was brought up in recitation...my comment before that line:

//might need to change "&&" to "||" TA's might have messed up!

i wanted to put something else but the proooooooofessor is going to look at it.

jba
10-03-2005, 06:13 PM
well if you change the && to || it just means if(true)

the problem is in here:

((charmode!=M_ASCII) || (charmode!=M_BINARY))

this is always true.


A) your name is not fred
B) your name is not tom

A || B == true for all possible guesses regardless of your name

Cosimo
10-03-2005, 06:14 PM
[ QUOTE ]
if((numbytes<0) && ((charmode!=M_ASCII) || (charmode!=M_BINARY)))

[/ QUOTE ]

If you've got empty #defines for M_ASCII and M_BINARY, this is gonna come out of the precompiler as:

if ((numbytes<0) && ((charmode!=) || (charmode!=)))

which is not gud.

mason55
10-03-2005, 07:49 PM
[ QUOTE ]
[ QUOTE ]
if((numbytes<0) && ((charmode!=M_ASCII) || (charmode!=M_BINARY)))

[/ QUOTE ]

If you've got empty #defines for M_ASCII and M_BINARY, this is gonna come out of the precompiler as:

if ((numbytes<0) && ((charmode!=) || (charmode!=)))

which is not gud.

[/ QUOTE ]

This is the correct answer. You need to define those constants as something if you're going to compare a variable to them. Plus the || should be &&. DeMorgan's theorem and all. Or you could make it ((charmode=M_ASCII) || (charmode=M_BINARY)). Same thing.

bravos1
10-03-2005, 08:13 PM
[ QUOTE ]
well if you change the && to || it just means if(true)

the problem is in here:

((charmode!=M_ASCII) || (charmode!=M_BINARY))

this is always true.


A) your name is not fred
B) your name is not tom

A || B == true for all possible guesses regardless of your name

[/ QUOTE ]

Not ALWAYS true. M_ASCII and M_BINARY could be eq. values. This would not always result in a true return value.

I highly doubt this would ever be the case here since these are #DEFINE'd, but just a small nit. For all intensive purposes, you are correct though and this line of code looks very suspitious. If M_ASCII and M_BINARY were regularly changing variables, then it could be valid, but it does not appear to be so in this case.

Sifmole
10-03-2005, 11:32 PM
[ QUOTE ]
[ QUOTE ]
the error isn't where you think it is. you'd have to post a whole lot more than this for us to tell you. it's probably something that seems totally unrelated to the error messages. like a missing semi-colon at the end of a line. or something.

[/ QUOTE ]

i'm thinking "or something". i don't think a missing semi colon will be missed by the compiler

[/ QUOTE ]

Is this like your first semester? I assure you a missing anything in the wrong place can cause very strange problems.

Sifmole
10-03-2005, 11:33 PM
[ QUOTE ]
../userprog/exception.cc: In function `char* UserToSystem(int, int, int)':
../userprog/exception.cc:107: parse error before `)' token
../userprog/exception.cc:107: parse error before `)' token
../userprog/exception.cc:129: parse error before `)' token
../userprog/exception.cc: In function `int SystemToUser(int, int, int, char*)':
../userprog/exception.cc:145: parse error before `)' token
../userprog/exception.cc:145: parse error before `)' token
../userprog/exception.cc:165: parse error before `)' token
../userprog/exception.cc:170: parse error before `)' token



oddly enough the line of code is:

if((numbytes<0) && ((charmode!=M_ASCII) || (charmode!=M_BINARY)))

i doubt i'll get any useful replies but my TA is taking forever so i thought hell i'll give this a whirl. numbytes, charmode is defined in the function declaration and M_ASCII/M_BINARY are #define b4 class starts.

[/ QUOTE ]

Show us the code, we'll solve it.

jason_t
10-03-2005, 11:36 PM
[ QUOTE ]
../userprog/exception.cc: In function `char* UserToSystem(int, int, int)':
../userprog/exception.cc:107: parse error before `)' token
../userprog/exception.cc:107: parse error before `)' token
../userprog/exception.cc:129: parse error before `)' token
../userprog/exception.cc: In function `int SystemToUser(int, int, int, char*)':
../userprog/exception.cc:145: parse error before `)' token
../userprog/exception.cc:145: parse error before `)' token
../userprog/exception.cc:165: parse error before `)' token
../userprog/exception.cc:170: parse error before `)' token



oddly enough the line of code is:

if((numbytes<0) && ((charmode!=M_ASCII) || (charmode!=M_BINARY)))

i doubt i'll get any useful replies but my TA is taking forever so i thought hell i'll give this a whirl. numbytes, charmode is defined in the function declaration and M_ASCII/M_BINARY are #define b4 class starts.

[/ QUOTE ]

You need to give us more code, there isn't enough here to see what's going on. Parsing errors are caused by a variety of reasons.

jason_t
10-03-2005, 11:37 PM
[ QUOTE ]
you know looking at it, it's happening only on M_ASCII and M_BINARY my lines for those are

#define M_ASCII
#define M_BINARY

i don't have any values for it. now i gotta figure out what the hell values i should give it.

OOT > TA's and professors combined.

[/ QUOTE ]

If you don't assign values to these after the code is passed through the C preprocessor your code will come out as

[ QUOTE ]
if((numbytes<0) && ((charmode!=) || (charmode!=)))

[/ QUOTE ]

which will never compile and is probably responsible for your parsing error unless you are also missing semicolons or braces above this line. You seem to have parsing errors at more than one line, but sometimes there is in fact just one offending line.

I don't know what you're doing, but there's possibly a logical error in your code too. cf. basic Boolean logic to make sure what you're doing is what you want.

10-03-2005, 11:37 PM
Whatever happened to Basic?

MonkeeMan
10-03-2005, 11:58 PM
[ QUOTE ]
Whatever happened to Basic?

[/ QUOTE ]

it went visual

DrSavage
10-04-2005, 12:00 AM
Without the complete code my best guess here is messed up #define, probably with a ";" terminating one or something like that.
edit: nvm, didn't read replies.

meleader2
10-04-2005, 12:37 PM
[ QUOTE ]
[ QUOTE ]
[ QUOTE ]
the error isn't where you think it is. you'd have to post a whole lot more than this for us to tell you. it's probably something that seems totally unrelated to the error messages. like a missing semi-colon at the end of a line. or something.

[/ QUOTE ]

i'm thinking "or something". i don't think a missing semi colon will be missed by the compiler

[/ QUOTE ]

Is this like your first semester? I assure you a missing anything in the wrong place can cause very strange problems.

[/ QUOTE ]

Like, oh my god!