Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

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.


 
 
  Published under the terms of the GNU General Public License Design by Interspire