Hey

Why does the following code comply in Dev-C++ and it DOESNT in MS VS 6.0?

#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <float.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

void main()
{
	int num;


	
	printf ("Number of positions");
	scanf ("%d",&num);
	int vector[num];
	
}

list errors.

The last line -- VC++ 6.0 is old style C which forces you to declare all objects at the beginning of function.

In dev-c++, add these options for the compiler -W -Wall -ansi -pedantic Then it won't compile under dev-c++ either.

And is there a way to make it comply in MS VS 6?

Like learn C properly?

As opposed to what you're doing at the moment, which is exploring what a particular compiler will let you get away with, then complaining because another compiler has stricter rules.

If you write portable C, the compiler doesn't matter.

#include <stdio.h>
#include <stdlib.h>

int main ( ) {  /* you got this wrong */
    int num;
    int *vector = NULL; /* useful habit for debugging */
    
    printf ("Number of positions");
    fflush(stdout); /* make sure the printf without a \n can be seen */

    if ( scanf ("%d",&num) == 1 && num > 0 ) {
        /* only do this if input was successful */
        vector = malloc( num * sizeof *vector );
        /* do something */
        free( vector );
    }

    return 0;
}

Can I use another complier using the MS VS 6 GUI?


That would be perfect for me.
Ive been taught C this way. Besides the point its stupid to do a malloc (in this case) and this is a few lines of a program.

Is there a way like in wxDev-C++ to change the complier from the VS one to the gcc one?

>>Ive been taught C this way.
You were taught wrong for most compilers.

The newest version of the C standards will allow you to declare objects anywhere you want, just like the C++ standards has done all along. The problem is you need to find a compiler that is new enough to implement that standard. VC++2008 also will not compile that code.

>>Ive been taught C this way.
You were taught wrong for most compilers.

The newest version of the C standards will allow you to declare objects anywhere you want, just like the C++ standards has done all along. The problem is you need to find a compiler that is new enough to implement that standard. VC++2008 also will not compile that code.

Still noone has answer another question...

Is there a way like in wxDev-C++ to change the complier from the VS one to the gcc one?

> Is there a way like in wxDev-C++ to change the complier from the VS one to the gcc one?
Like reading the tutorials on the site homepage perhaps?

http://wxdsgn.sourceforge.net/?q=node/6
Specifically,
"Setting Up wxDev-C++ for compiling with Visual C++ 2005"

But if your solution to every programming problem is to change compilers, then you're in for a rough ride.

I use 2 or 3 different compilers on a daily basis, and couldn't give a monkeys which compiler I'm using.
That's because I program to the language and not the compiler.

commented: -That's because I program to the language and not the compiler.- Amen +17
Member Avatar for iamthwee

>Why does the following code comply in Dev-C++ and it DOESNT in MS VS 6.0?

Ask it nicely, then it might comply.

I already asked nicely.


And about learning the language instead of the compiler, I dont care much as programming is not something I want to dominate and dont see it as my possible future career.

I already asked nicely.

And? What did the compiler say? :|

And about learning the language instead of the compiler, I dont care much as programming is not something I want to dominate and dont see it as my possible future career.

The compiler actually does care, so learn standard C it'll solve your problem.
You can just copy-paste Salem's code so what's the big problem here?

I thought you ment to ask you guys nicely.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.