Very Weird Syntax Errors...

Hey, I'm new to this community, and I want to start off right - so here's my first question (lol):

I'm writing code for an AI project that I'm working on, and for the most part it is going pretty well. But I'm compiling this code and I'm getting syntax errors that really don't make any sense to me at all. Similar code had worked on my old computer (I just switched, maybe that has something to do with it?), but now it doesn't and I'm confused. Here's an example of code:

PL_ACT EXCEPTZ::get_obj_EXC(__int64 statz) {
PL_ACT empty;
if (statz == 0){return EXC_NONE;}
for (int i = 0; (pow(2,i)) < EX_sad; i++)
{
if ((statz)&(__int64)(pow(2,i))){ return *((&EXC_NONE)+i);}
}
}

And the errors are things concerning this line: "if (statz == 0){return EXC_NONE;}". The compiler is saying things like "error '='" and "missing ';' before ')'," or "missing ';' before '{'." I see nothing wrong with the code, and it does it throughout the whole project for if-then statements. This may be a simple problem to fix, and if so, I'm sorry for waisting anyone's time, but I can't figure it out. Can you help me out? ALL help would be greatly appreciated, because I can't really move on to the REAL problems with the code until I get past this. So thanks in advance.

Comments

  • : Hey, I'm new to this community, and I want to start off right - so here's my first question (lol):
    :
    : I'm writing code for an AI project that I'm working on, and for the most part it is going pretty well. But I'm compiling this code and I'm getting syntax errors that really don't make any sense to me at all. Similar code had worked on my old computer (I just switched, maybe that has something to do with it?), but now it doesn't and I'm confused. Here's an example of code:
    :
    : PL_ACT EXCEPTZ::get_obj_EXC(__int64 statz) {
    : PL_ACT empty;
    : if (statz == 0){return EXC_NONE;}
    : for (int i = 0; (pow(2,i)) < EX_sad; i++)
    : {
    : if ((statz)&(__int64)(pow(2,i))){ return *((&EXC_NONE)+i);}
    : }
    : }
    :
    : And the errors are things concerning this line: "if (statz == 0){return EXC_NONE;}". The compiler is saying things like "error '='" and "missing ';' before ')'," or "missing ';' before '{'." I see nothing wrong with the code, and it does it throughout the whole project for if-then statements. This may be a simple problem to fix, and if so, I'm sorry for waisting anyone's time, but I can't figure it out. Can you help me out? ALL help would be greatly appreciated, because I can't really move on to the REAL problems with the code until I get past this. So thanks in advance.
    :
    :
    ok, well for one, what compiler are you using?
    two, you aren't ending some of your lines with a ";" as you should, so for example(dont add the **, it's just to point it out):
    PL_ACT EXCEPTZ::get_obj_EXC(__int64 statz) {
    PL_ACT empty;
    if (statz == 0){return EXC_NONE;}**;**
    for (int i = 0; (pow(2,i)) < EX_sad; i++)
    {
    if ((statz)&(__int64)(pow(2,i))){ return *((&EXC_NONE)+i);}**;**
    }**;**
    }**;**

    got it?
    reply if it helped, otherwise im sorry if it did'nt.
    plus make sure you dont have spelling error! (omg, that just happened to me 5 minutes ago and it was hell! :P)

    Lynx
  • jasonjason United Kingdom
    [b][red]This message was edited by jason at 2004-10-31 12:17:34[/red][/b][hr]
    A classic example on why you should layout your code properly.
    [code]
    PL_ACT EXCEPTZ::get_obj_EXC( __int64 statz )
    {
    PL_ACT empty;
    if ( statz == 0 )
    {
    return EXC_NONE;
    }

    for ( int i = 0; ( pow( 2,i ) ) < EX_sad; i++ )
    {
    if ( ( statz ) & ( __int64 )( pow( 2,i ) ) )
    {
    return *( ( &EXC_NONE )+i );
    }
    }
    }

    [/CODE]
    [red]Regards, Jason[/red]



  • [code]
    return *( ( &EXC_NONE )+i );
    [/code]

    What the heck is this? what is EXC_NONE, an array of ints? If it is, then you sure beat the bush awfully hard to get the array element.
  • [b][red]This message was edited by coreman2200 at 2004-10-31 15:0:18[/red][/b][hr]
    Sorry it has taken my so long to reply to any of these. I'm going to try out all of your ideas now, and thanks. I'm using VC++ 6.0, to answer that question, by the way. And I know that whole structure is really akward, but I figured that was the best way to do it. EXC_NONE is an integer in the class EXCEPTZ. I just have it written like I'm getting the value from some array because I have all of the values defined like this:

    int EXC_NONE, EXC_ISTHIS, EXC_ISTHAT, EXC_SOMETHINGELSE....

    And I remember reading somewhere a while back that in memory they will all be lined up beside each other in memory. Well, I'll be back with the results of my efforts and your contributions. Thanks again.




    ----Update---
    No - still doesn't work.. I don't get it. Again, I've made some changes to shorten the code up (that's why it looks so weird - before it was a LONG list of 'if (this == that){return this_here;}' type things. Now I have it so the this' (which are defines I have set up in another .h file) and the that's (which are values in whichever class) are aligned, so I can just do a for loop going down the list. I'm not exactly sure if this is faster or not, but it definately does look a lot less repetitive and messy. The point is, other than shortening it, I haven't made many changes at all. Now things that I think should work aren't and I don't understand why. And I have the same 2 or three errors throughout the entire list of errors. Are you guys sure it is something I did?


  • : int EXC_NONE, EXC_ISTHIS, EXC_ISTHAT, EXC_SOMETHINGELSE....
    :
    : And I remember reading somewhere a while back that
    : in memory they will all be lined up beside each other
    : in memory.

    They [italic]may[/italic] be, but it's not safe to assume that and write code that relies on it. If you want an array, create an array. If you want the address of EXC_ISTHIS, use &EXC_ISTHIS not &EXC_NONE + 1.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories