- publishing free software manuals
An Introduction to GCC - for the GNU compilers gcc and g++
by Brian J. Gough, foreword by Richard M. Stallman
Paperback (6"x9"), 144 pages
ISBN 0954161793
RRP £12.95 ($19.95)

"An excellent introduction... fills a much-needed niche in the marketplace" --- Association of C and C++ Users book review (Issue 16-4, August 2004) Get a printed copy>>>

3.3.2 Strict ANSI/ISO

The command-line option -pedantic in combination with -ansi will cause gcc to reject all GNU C extensions, not just those that are incompatible with the ANSI/ISO standard. This helps you to write portable programs which follow the ANSI/ISO standard.

Here is a program which uses variable-size arrays, a GNU C extension. The array x[n] is declared with a length specified by the integer variable n.

int 
main (int argc, char *argv[])
{
  int i, n = argc;
  double x[n];

  for (i = 0; i < n; i++)
    x[i] = i;

  return 0;
}

This program will compile with -ansi, because support for variable length arrays does not interfere with the compilation of valid ANSI/ISO programs--it is a backwards-compatible extension:

$ gcc -Wall -ansi gnuarray.c

However, compiling with -ansi -pedantic reports warnings about violations of the ANSI/ISO standard:

$ gcc -Wall -ansi -pedantic gnuarray.c
gnuarray.c: In function `main':
gnuarray.c:5: warning: ISO C90 forbids variable-size 
  array `x'

Note that an absence of warnings from -ansi -pedantic does not guarantee that a program strictly conforms to the ANSI/ISO standard. The standard itself specifies only a limited set of circumstances that should generate diagnostics, and these are what -ansi -pedantic reports.

ISBN 0954161793An Introduction to GCC - for the GNU compilers gcc and g++See the print edition