How to call a C compiler under gcc

According to my memory, the following code fragment should compile in C ++, but not in C. The only problem is how to check it? It is compiled with g ++ as well as gcc. I assume that g ++ is the C ++ compiler and gcc is the C compiler. I tried this with mingw on Windows. I'm right? if not, then how to compile it using the C compiler.

int main() {
 const int i = 1;
 const int j = 2;
 const int k = 3;

 int array[i + j + k];
 return 0;
}
+3
source share
4 answers

No, this will be compiled in C99, which supports variable length arrays . To get strict C89 behavior, try compiling with:

gcc -std=c89 -pedantic-errors

This gives:

error: ISO C90 forbids variable length array β€˜array’

c89 C89, , C89.

+11

C, C99, gcc-. , :

peregrino:$ gcc -pedantic -std=c89 src/maybe_pedantic.c 
src/maybe_pedantic.c: In function β€˜main’:
src/maybe_pedantic.c:6: warning: ISO C90 forbids variable length array β€˜array’
+3

gcc -x

gcc --help :

# -x <language>            Specify the language of the following input files
#                          Permissible languages include: c c++ assembler none
#                          'none' means revert to the default behavior of
#                          guessing the language based on the file extension

C-.

+2

++ C99 ( C89)

g++, gcc

gcc C99

, C?

*.cpp *.c.

0

Source: https://habr.com/ru/post/1734497/


All Articles