Thread: MSVS compiler errors

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    42

    MSVS compiler errors

    I am getting some strange compiler errors. I had this code working fine this morning and unless Im losing my marbles, I dont remember changing anything except writing some new functions. I commented out most of the program and am still getting compiler errors. I am getting illegal use and syntax error on line 19, 20 and 21 (declarations under main). Any suggestions? Thanks in advance.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <time.h>
    #define pause system("pause")
    #define cls system("cls")
    #define flush fflush(stdin)
    
    
    typedef struct {
        char word[10];
    }WORDS;
    
    
    //int enterWords(WORDS userWords[]);
    //void inputWords(WORDS userWords[], char** board, int totalWords);
    
    
    int main (){
        srand(time(NULL));
        WORDS userWords[16];
        char **board;
        int i, n, numWords;
    
        return 0;
    
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should post the smallest and simplest program that you expect to compile but which results in the compile error, and also post the exact compile error messages, including line numbers.

    As it stands, gcc 4.6.3 finds no fault with your program that would cause it to refuse to compile.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    Your compiler doesn't support mixed declarations and code.

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    42
    This is the smallest portion of the above code that compiles in MSVS 12. As soon as I un-comment any of the other three declarations the compiler gives me an error. This is the same code I was working with this morning with no problems. At first, I though I might be working on another source file, but after exiting and re-opening the project, I get the same errors.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <time.h>
    #define pause system("pause")
    #define cls system("cls")
    #define flush fflush(stdin)
    
    
    typedef struct {
        char word[10];
    }WORDS;
    
    
    //int enterWords(WORDS userWords[]);
    //void inputWords(WORDS userWords[], char** board, int totalWords);
    
    
    int main (){
        srand(time(NULL));
        //WORDS userWords[16];
        //char **board;
        //int i=0, n=0, numWords=0;
    
    
        return 0;
    }

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What are the exact error messages?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Hint for LL: ISO C90

    Hint for OP: `srand' is not a declaration.

    The three commented lines are declarations.

    [Edit]
    Also, `fflush(stdin)' isn't a thing that will work... or at least isn't portable.
    [/Edit]

    Soma

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by phantomotap
    Hint for LL: ANSI C
    Hint for phantomotap: C99 comments in C89/C90 code are dumb.

    But yeah, you're probably right since this is MSVS.

    EDIT:
    Eh, how did Barney McGrew's post go missing from my previous reading of this thread? Might be a timing thing.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Jan 2013
    Posts
    42
    I am getting:

    illegal use of this type of expression, syntax error missing ; and subscript requires an array pointer type for line 19 (WORDS userWords[16])

    syntax error missing ; for lines 20 and 21 (char **board and int i, n, numWords=0)

    Ive used the fflush before, I know its frowned upon but Ive commented it out as well with no success.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Bah, if Barney McGrew and phantomotap are spot on, then the error message does not provide very much useful information (gcc will directly tell you about mixed declarations and code, if I remember correctly).

    As a test, try:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <time.h>
    #define pause system("pause")
    #define cls system("cls")
    #define flush fflush(stdin)
     
     
    typedef struct {
        char word[10];
    }WORDS;
     
     
    /*int enterWords(WORDS userWords[]);
    void inputWords(WORDS userWords[], char** board, int totalWords);*/
     
     
    int main (){
        
        WORDS userWords[16];
        char **board;
        int i=0, n=0, numWords=0;
        srand(time(NULL));
     
        return 0;
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    [Edit]
    For the OP: "GCC" is a free suite supporting C and many other languages. I highly recommend installing it. (Search for "TDM" and "MinGW" and you'll find a common distribution of "GCC" for "Windows".)

    Note: I'm not suggesting that you toss "MSVC"; it is very helpful to have multiple compilers installed. If nothing else, as laserlight suggests, "GCC" may have better warnings for any given problem. The reverse is also true. By having multiple compilers and learning to develop against the interpretation of the standard implemented by a few different compilers you learn something of a refined form of C that is more portable and highly conforming making you, in the opinion of many, a much better developer.
    [/Edit]

    But yeah, you're probably right since this is MSVS.
    O_o

    You may feel free to try "GCC", "Sun", and, I believe, "Intel" compilers, for example, as without special effort (This effort would be a flag like `-ansi' for "GCC".) a lot of compilers allow C++ comments even in C90 mode. You, basically, have to enable "strict C90" mode to enable warnings/errors for such extensions.

    Eh, how did Barney McGrew's post go missing from my previous reading of this thread?
    Hah.

    LL got ninja'd. I'm happy again. ^_^

    Soma
    Last edited by phantomotap; 03-25-2013 at 09:51 PM.

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by phantomotap
    You may feel free to try "GCC", "Sun", and, I believe, "Intel" compilers, for example, as without special effort (This effort would be a flag like `-ansi' for "GCC".) a lot of compilers allow C++ comments even in C90 mode. You, basically, have to enable "strict C90" mode to enable warnings/errors for such extensions.
    I'm talking about the programmer, not the compiler.

    Quote Originally Posted by phantomotap
    LL got ninja'd.
    By more than 2 minutes too. I'm getting not so "fast and bright" like laser in my old age.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I'm talking about the programmer, not the compiler.
    Ah, well, that is entirely different container of aquatic animal.

    I find the `fflush(stdin)' thing to be more problematic than the comment, but your mileage may vary.

    [Edit]
    laserlight likes this.
    ;_;

    Why do you only love me when I'm being silly?
    [/Edit]

    [Edit]
    I think I know.

    I was born in the year of the dog; I'm big, silly, and fluffy.

    You think I'm a puppy! ^_^
    [/Edit]

    Soma
    Last edited by phantomotap; 03-25-2013 at 09:58 PM.

  13. #13
    Registered User
    Join Date
    Jan 2013
    Posts
    42
    I'm sorry guys, I should have mentioned that this program is being written for school assignment. The instructor has us use MSVS because that is what he uses. That being said, The program compiled and ran fine earlier today, the only difference is I had a lot more code. I started commenting out various functions and declarations to eliminate the problem but as you can see above, it did not work. At this point the only thing I can think of uninstalling and re-installing MSVS 12.

  14. #14
    Registered User
    Join Date
    Jan 2013
    Posts
    42
    Thanks all, I want sure what was being conveyed when everyone was saying mixed declarations and such. Moving srand underneath the declarations worked. Appreciate the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. More Compiler Errors...
    By P3nGu1N in forum C Programming
    Replies: 11
    Last Post: 03-13-2009, 10:38 AM
  2. Compiler errors
    By Beowolf in forum C++ Programming
    Replies: 12
    Last Post: 10-31-2007, 09:25 AM
  3. Compiler errors
    By ICool in forum C Programming
    Replies: 9
    Last Post: 10-18-2007, 08:01 AM
  4. Compiler errors
    By Dark_Phoenix in forum Game Programming
    Replies: 2
    Last Post: 11-05-2006, 10:28 AM
  5. Compiler errors
    By BellosX in forum C Programming
    Replies: 2
    Last Post: 09-21-2001, 03:24 AM