DevC++ and Visual Studio problem

This is a discussion on DevC++ and Visual Studio problem within the C Programming forums, part of the General Programming Boards category; Hello. I get errors trying to compile C source written and working in DevC++. When I paste it in Visual ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    16

    DevC++ and Visual Studio problem

    Hello. I get errors trying to compile C source written and working in DevC++. When I paste it in Visual Studio 6.0 it shows strange errors and won't compile. Can you help me with this?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    What errors do you get?
    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
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It would help us if you give us the exact error messages, and perhaps a short bit of code to show the problem. Yes, there are differences between for exampel Visual Studio 6.0 and gcc that is used behind the scenes in Dev-C++. Sometimes that's simply that one has extensions that the other one doesn't support, for example. Also VC 6 may have "issues" when it comes to standard compliance - or so I've heard.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    16
    Here are examples.

    The code:

    Code:
    for(k = 0; k <= num_people; k++)
    gives error

    Code:
    test.c(190) : error C2065: 'k' : undeclared identifier
    although I have declared the identifier as int k; before the for loop.

    Code:
    strcpy(name[j], temp);
    with error

    Code:
    test.c(183) : warning C4024: 'strcpy' : different types for formal and actual parameter 2
    and error
    Code:
    test.c(178) : error C2106: '=' : left operand must be l-value
    The code
    Code:
    int i,j,k,count;
    has error
    Code:
    test.c(167) : error C2143: syntax error : missing ';' before 'type'
    but there's no error in fact.

    There are some more errors and warnings.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    Well, one way to find the problem is to write the smallest and simplest program that compiles on Dev-C++'s compiler yet fails to compile on MSVC6. Post that here with the error messages, and we'll see what's wrong.
    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
    Registered User
    Join Date
    Dec 2007
    Posts
    16
    laserlight, do you think it might be something with the encoding of the file?

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't think it's the encoding. However, I suspect that if you post the code around this point:
    Code:
    test.c(167) : error C2143: syntax error : missing ';' before 'type'
    we will be able to advice you further.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Dec 2007
    Posts
    16
    Code:
    if(num_people == 0){
                      printf("No people records.");
                      return 0;
                      }    
        int i,j,k,count; // this is test.c (167) error C2143: syntax error : missing ';' before 'type'
        float average_age = 0;
        int sum_ages = 0;
        char temp[30];
        int  temp_ages[30];
        
        for (i=0; i<num_people; i++){
              for (j=i+1; j<num_people; j++){
    	          if (strcmp(name[i], name[j]) > 0){
                	     strcpy(temp, name[i]);
                         temp_ages[i] = age[i];
                	     
                	     strcpy(name[i], name[j]);
                	     age[i] = age[j];
                	     
                	     strcpy(name[j], temp);
                	     age[j] = temp_ages[i];
                      }
              }

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    In standard C (as opposed to extensions in gcc) you have to declare all variables at the begining of the block. You have code first, then variable declarations. - you could work around it with something like:
    Code:
    if(num_people == 0){
                      printf("No people records.");
                      return 0;
                      }    
    
        {
        int i,j,k,count; // this is test.c (167) error C2143: syntax error : missing ';' before 'type'
        float average_age = 0;
        int sum_ages = 0;
        char temp[30];
        int  temp_ages[30];
        
        for (i=0; i<num_people; i++){
              for (j=i+1; j<num_people; j++){
    	          if (strcmp(name[i], name[j]) > 0){
                	     strcpy(temp, name[i]);
                         temp_ages[i] = age[i];
                	     
                	     strcpy(name[i], name[j]);
                	     age[i] = age[j];
                	     
                	     strcpy(name[j], temp);
                	     age[j] = temp_ages[i];
                      }
              }
    
        }
    If you compile in gcc using the "-ansi" switch to tell the compiler that you only want code that is compliant with ISO C90 standard, rather than "gcc compliant" which is the default.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Dec 2007
    Posts
    16
    matsp, is there any way to tell the MSVC 6.0 compiler to compile with "-ansi" - as I understood that's causing the errors.

    Surrounding with braces, as you said, works - the error in line 167 is gone, so is it possible to change compile parameters in MSVC 6.0 so it'd behave like DevC++'s compiler?

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Etdim View Post
    matsp, is there any way to tell the MSVC 6.0 compiler to compile with "-ansi" - as I understood that's causing the errors.

    Surrounding with braces, as you said, works - the error in line 167 is gone, so is it possible to change compile parameters in MSVC 6.0 so it'd behave like DevC++'s compiler?
    No, the problem is that you are using extensions beyond "ansi" that are only available in gcc. You could change it to compile as C++ which allows these sort of constructions, but chances are that other things that are different between C++ and C will trip you up - and that can get very tricky to solve if you don't understand those differences.

    If you then use -ansi on your gcc compile, it will let you know when you've "broken" things.

    My actual suggestion is that you move your variable declarations to the beginning of the function. That should work in ALL compilers [that have been produced in the last 10 years or so] with no problems.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    The problem is that it is gcc that has the extension, not MSVC6. So the solution is to change your code to comply with the standard, upon which it will work on both compilers.
    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

  13. #13
    Registered User
    Join Date
    Dec 2007
    Posts
    16
    Ok, now I understand. But what about errors like
    Code:
    test.c(147) : error C2143: syntax error : missing ';' before 'type'
    test.c(116) : warning C4047: 'function' : 'struct _iobuf *' differs in levels of indirection from 'int '
    test.c(150) : warning C4024: 'fprintf' : different types for formal and actual parameter 1
    test.c(74) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
    test.c(129) : error C2275: 'FILE' : illegal use of this type as an expression
    How could I understand what's causing these errors/warnings?

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Sounds like more of the same, but without seeing the code that those errors refer to, it's very hard to say. Errors don't mean much without the actual code...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,169
    This is not properly indented code.
    I don't suggest you indent so much as you did with your if. And all ending } should be on the same level as the block element - such as the if or while or whatever it is you're using.
    And you're ALSO mixing spaces and tabs. Not very good. Usually messes up code outside your editor. Use only spaces or only tabs - it's for the best. Recommend tabs.

    Your if is also not on the correct level. It should be on the same level as all the other code inside the function. No code except function should appear without any preceding spaces or tabs.

    Quote Originally Posted by Etdim View Post
    Code:
    	if(num_people == 0){
    		printf("No people records.");
    		return 0;
    	}    
    	int i,j,k,count; // this is test.c (167) error C2143: syntax error : missing ';' before 'type'
    	float average_age = 0;
    	int sum_ages = 0;
    	char temp[30];
    	int  temp_ages[30];
        
    	for (i=0; i<num_people; i++){
    		for (j=i+1; j<num_people; j++){
    			if (strcmp(name[i], name[j]) > 0){
    			strcpy(temp, name[i]);
    			temp_ages[i] = age[i];
                	     
    			strcpy(name[i], name[j]);
    			age[i] = age[j];
                	     
    			strcpy(name[j], temp);
    			age[j] = temp_ages[i];
    		}
    	}
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

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