Thread: Compiler issues in C in MSVisStudio2010 cl cmd compiler vs other (gcc/tcc)

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    55

    Compiler issues in C in MSVisStudio2010 cl cmd compiler vs other (gcc/tcc)

    Hi
    I have recently tried compiling C code 'secondchess.c' in Win7 with MSVisStudio2010 cl cmd compiler & this returns a whole bunch of errors/warnings etc. I also have TCC compiler on my Win7 machine & used it to compile the code which it did without any complaint!
    See my thread on chess2u forum about this:
    SecondChess - Page 2

    I am a very inexperienced coder but would like to try to use standards compliant code & so I am very grateful if someone can help me sort out the errors this code gets in MSvisStudio2010 cl compiler.
    (As in my chess forum post I have spent a lot of time already trying to fix this but with no success-please remember I am an amateur programmer & new to C/C++).

    These are the first errors given:
    Code:
    secondchess.c(785) : error C2143: syntax error : missing ';' before 'type'
    secondchess.c(789) : error C2143: syntax error : missing ';' before 'type'
    secondchess.c(792) : error C2065: 'i' : undeclared identifier
    & I have tried to fix them but no result & there are so many more errors! Why does MSVisStudio2010 cl compiler baulk at this & yet tcc (& gcc-I think but I have not used gcc as I'm on Win7) doesn't?

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    The problem was, the source code wasn't compiled originally with strict C89 conformance.

    Code:
    int Eval()
    {
    
       //!! this is a statement
       count_evaluations++;
    
       //!! this is a declaration
       /* A counter for the board squares */
       int i;
    
       /* The score of the position */
       int score = 0;
    Most modern compilers now support C99, which allows such things.

    But MS will never update their C compiler to C99, so you're stuck with just C89 on that compiler.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Without seeing the actual code, I can only surmise you're running into Microsoft's unwillingness to update their C compiler to a newer standard than C89 (I think that's the one they adhere to). In C89 and prior, all type declarations must precede any actual code.

    EDIT: Damn, too slow!

  4. #4
    Registered User
    Join Date
    Apr 2012
    Posts
    55
    Quote Originally Posted by Salem View Post
    The problem was, the source code wasn't compiled originally with strict C89 conformance.

    Code:
    int Eval()
    {
    
       //!! this is a statement
       count_evaluations++;
    
       //!! this is a declaration
       /* A counter for the board squares */
       int i;
    
       /* The score of the position */
       int score = 0;
    Most modern compilers now support C99, which allows such things.

    But MS will never update their C compiler to C99, so you're stuck with just C89 on that compiler.
    Thanks for your quick & helpful reply. I am googling this to find more info & how to fix it.
    I have run secondchess.c as an empty project in MSVisStudio2010 but still get many errors eg:
    1> secondchess.c
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(525): warning C4013: 'IsInCheck' undefined; assuming extern returning int
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(526): warning C4013: 'IsAttacked' undefined; assuming extern returning int
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(806): error C2143: syntax error : missing ';' before 'type'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(809): error C2143: syntax error : missing ';' before 'type'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(812): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(812): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(812): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(814): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(818): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(818): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(822): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(825): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(825): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(828): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(828): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(831): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(831): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(834): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(834): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(837): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(837): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(841): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(843): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(843): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(845): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(848): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(848): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(851): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(851): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(854): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(854): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(857): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(857): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(860): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(860): error C2065: 'i' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(867): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(868): error C2065: 'score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1561): warning C4013: 'Quiescent' undefined; assuming extern returning int
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1659): error C2275: 'clock_t' : illegal use of this type as an expression
    1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\time.h(82) : see declaration of 'clock_t'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1659): error C2146: syntax error : missing ';' before identifier 'start'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1659): error C2065: 'start' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1660): error C2275: 'clock_t' : illegal use of this type as an expression
    1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\time.h(82) : see declaration of 'clock_t'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1660): error C2146: syntax error : missing ';' before identifier 'stop'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1660): error C2065: 'stop' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1661): error C2143: syntax error : missing ';' before 'type'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1664): error C2065: 'start' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1665): error C2065: 'start' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1671): error C2065: 'stop' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1672): error C2065: 't' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1672): error C2065: 'stop' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1672): error C2065: 'start' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1672): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1673): error C2065: 't' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1675): error C2143: syntax error : missing ';' before 'type'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1678): error C2065: 'decimal_score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1678): error C2065: 'decimal_score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1685): error C2065: 'decimal_score' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1685): error C2065: 't' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1828): error C2275: 'MOVE' : illegal use of this type as an expression
    1> c:\rpd_programming+computing\rpd_chess_programming \secondchess\secondchess.c(138) : see declaration of 'MOVE'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1828): error C2146: syntax error : missing ';' before identifier 'moveBuf'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1828): error C2065: 'moveBuf' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1828): error C2109: subscript requires array or pointer type
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1829): error C2143: syntax error : missing ';' before 'type'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1914): error C2065: 'movecnt' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1914): error C2065: 'moveBuf' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1914): warning C4047: 'function' : 'MOVE *' differs in levels of indirection from 'int'
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1914): warning C4024: 'Gen' : different types for formal and actual parameter 2
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1917): error C2065: 'movecnt' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1918): error C2065: 'moveBuf' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1918): error C2109: subscript requires array or pointer type
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1918): error C2065: 'moveBuf' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1918): error C2109: subscript requires array or pointer type
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1926): error C2065: 'moveBuf' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1926): error C2109: subscript requires array or pointer type
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1930): error C2065: 'moveBuf' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1930): error C2109: subscript requires array or pointer type
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1934): error C2065: 'moveBuf' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1934): error C2109: subscript requires array or pointer type
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1938): error C2065: 'moveBuf' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1938): error C2109: subscript requires array or pointer type
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1944): error C2065: 'moveBuf' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1944): error C2109: subscript requires array or pointer type
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1947): error C2065: 'moveBuf' : undeclared identifier
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1947): error C2109: subscript requires array or pointer type
    1>c:\rpd_programming+computing\rpd_chess_programmi ng\secondchess\secondchess.c(1947): error C2198: 'MakeMove' : too few arguments for call

    Any more help please... Thanks

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How much of the work are you prepared to do?

    Because we're not a "I found some code, please fix it for me" kind of site. These kinds of fixes are best done by the authors/maintainers so that everyone benefits.

    > 1>c:\rpd_programming+computing\rpd_chess_programm i ng\secondchess\secondchess.c(814): error C2065: 'i' : undeclared identifier
    > 1>c:\rpd_programming+computing\rpd_chess_programm i ng\secondchess\secondchess.c(818): error C2065: 'score' : undeclared identifier
    All these would be fixed if you moved count_evaluations++; down a few lines.

    Similarly, look at the other similar error messages caused by mixing declarations and statements. Move the statements!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    Without looking at the code at all, perhaps try building it as C++. Since C++ allows you to mix declarations and other code, you'd at least move on to a new list of errors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having issues with my compiler..
    By SirFloofy in forum C++ Programming
    Replies: 11
    Last Post: 02-26-2012, 02:10 PM
  2. C and Cpp GCC Compiler Issues
    By Bangonkali in forum C Programming
    Replies: 15
    Last Post: 12-12-2010, 11:01 PM
  3. Replies: 2
    Last Post: 02-04-2008, 02:34 AM
  4. GNU C++ Compiler Issues!
    By code_writer in forum Tech Board
    Replies: 4
    Last Post: 05-12-2007, 11:03 AM
  5. Compiler Issues
    By marliwht in forum C Programming
    Replies: 6
    Last Post: 10-21-2005, 12:57 PM