Search notes:

gcc -std

Choose the c standard according to which a compilation unit should be compiled, for example
-std=c89 is equivalent to using the -ansi option.

g++

The standards for C++ start with c++:

Combination with -pedantic

-std=c90 makes gcc accept a superset of C90 (for example the more flexible C99 variable declarations anywhere in the program). In order to make gcc enforce the C90 standard, the -pedantic flag needs to also be specified.
This is demonstrated in the following program. It compiles without warning if compiled with either However, if compiled with one of the following, it issues a warning about the mixed declaration and code:
/* 
  
   gcc -std=c89           variable-declaration.c    # OK
   gcc -std=c89 -pedantic variable-declaration.c    # warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   gcc -std=c90           variable-declaration.c    # OK
   gcc -std=c90 -pedantic variable-declaration.c    # warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   gcc -std=c99           variable-declaration.c    # OK
   gcc -std=c99 -pedantic variable-declaration.c    # OK

*/

#include <stdio.h>

int foo() {
   return 42;
}

int main() {

  printf("Hello world.\n");

  int i = foo();

  printf("i = %d\n", i);

}
Github repository about-gcc, path: /options/std/variable-declaration.c

See also

The predefined preprocessor macro __cplusplus.
GNU extensions can be chosen with -std=gnu++98 etc.
C standards
GCC options

Index