Like Tree2Likes
  • 1 Post By laserlight
  • 1 Post By phantomotap

MSVS compiler errors

This is a discussion on MSVS compiler errors within the C Programming forums, part of the General Programming Boards category; I am getting some strange compiler errors. I had this code working fine this morning and unless Im losing my ...

  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
    21,636
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,636
    What are the exact error messages?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    4,231
    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
    21,636
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,636
    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;
    }
    generaltso78 likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    4,231
    [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.
    laserlight likes this.

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    4,231
    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, 09:28 AM
  5. Compiler errors
    By BellosX in forum C Programming
    Replies: 2
    Last Post: 09-21-2001, 03:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21