don't click here

Compiler Bug?

Discussion in 'Technical Discussion' started by saxman, Jul 28, 2009.

  1. saxman

    saxman

    Oldbie Tech Member
    I get this:

    Code (Text):
    1. obj01.c: In function `Floor_ChkTile':
    2. obj01.c:3081: parse error before `short'
    3. obj01.c:3087: `x' undeclared (first use in this function)
    4. obj01.c:3087: (Each undeclared identifier is reported only once
    5. obj01.c:3087: for each function it appears in.)
    6. obj01.c:3088: `y' undeclared (first use in this function)
    The code it's reading is this:

    Code (Text):
    1. int Floor_ChkTile(){
    2.     WriteLog("Floor_ChkTile()");    TabLog(1);    RegLog();
    3.     short x = (((short)d3)>>4);
    4.     short y = (((short)d2)>>4);
    5.     // this function is customized for ProSonic
    6.     // d3 is a modified 'p->x_pos'
    7.     // d2 is a modified 'p->y_pos'
    8.     
    9. &nbsp;&nbsp;&nbsp;&nbsp;if(x < 0) x = ((z.TMAP[tmap_ptr-2]+1) * (2<<tilesize)) - x;
    10. &nbsp;&nbsp;&nbsp;&nbsp;if(y < 0) y = ((z.TMAP[tmap_ptr-1]+1) * (2<<tilesize)) - y;
    11. &nbsp;&nbsp;&nbsp;&nbsp;
    12. &nbsp;&nbsp;&nbsp;&nbsp;a1 = COMPILED_MAP[
    13. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(x % ((z.TMAP[tmap_ptr-2]+1) * (2<<tilesize)))
    14. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ ((y % ((z.TMAP[tmap_ptr-1]+1) * (2<<tilesize)))
    15. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* ((z.TMAP[tmap_ptr-2]+1) * (2<<tilesize)))];
    16. &nbsp;&nbsp;&nbsp;&nbsp;//a1 = ReadBlock(&z, (short)d3, (short)d2);
    17. &nbsp;&nbsp;&nbsp;&nbsp;RegLog();&nbsp;&nbsp;&nbsp;&nbsp;TabLog(-1);&nbsp;&nbsp;&nbsp;&nbsp;return 0;
    18. }
    What the heck is going on?! If I take out the WriteLog("Floor_ChkTile()"); TabLog(1); RegLog(); line, it works compiles just fine. I use WriteLog(), TabLog(), and RegLog() in my other functions just the same way without any issues, but it complains about it in the Floor_ChkTile() function. Is there something I'm going wrong, or is the compiler being retarded?
     
  2. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,718
    1
    0
    being an asshole =P
    It's pure C, right? Because C doesn't allow variables to be declared after any code. Maybe the newest standards (didn't check that), but of course not all compilers follow that.
     
  3. GerbilSoft

    GerbilSoft

    RickRotate'd. Administrator
    2,972
    85
    28
    USA
    rom-properties
    Basically, what Sik said. It looks like you're using Microsoft Visual C++, which still doesn't support variable declarations after the start of a block when compiling C code. It does support it when compiling C++ code, though.
     
  4. saxman

    saxman

    Oldbie Tech Member
    Oh shoot, you're right. I completely forgot about that. I didn't even realize I was doing it. Thanks for pointing that out! Issue resolved.