Question

I'm in a windows platform, is there any way to compile a program in command line in c99 mode , without having to type -std=c99 in every statement ? my current gcc version is 4.4.1 .

Était-ce utile?

La solution

gcc does not provide a way to specify command-line arguments via, for example, environment variables. If you want the effect of -std=c99, then at some level you're going to have to invoke the gcc command with that argument.

If you're invoking gcc from a Unix-like command shell, such as the one used with Cygwin, there might already be a c99 command. POSIX requires such a command (it would be a wrapper around the gcc command). I don't have a Cygwin installation at the moment, so I can't check it. If it's not there, you can define a shell function:

c99() {
    gcc -std=c99 "$@"
}

If you're invoking it from a Windows MS-DOS-style command prompt, you can create a batch file called c99.cmd containing:

gcc -std=c99 %1 %2 %3 %4 %5 %6 %7 %8 %9

and put it somewhere in your %PATH%.

Note that the latter method only handles up to 9 command-line arguments, which will usually be enough. (I think there are ways to handle more.)

You can of course add more arguments, like -pedantic -Wall -Wextra if you want to catch more errors at compile time.

Note that I've named the command c99 rather than gcc so that it doesn't try to invoke itself recursively. If you really want to be able to invoke it as gcc, you can specify the full path to the gcc executable (you'll have to find out what that is on your system). But that will make it more difficult to invoke gcc without the extra arguments.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top