Add Book to My BookshelfPurchase This Book Online

Chapter 1 - Introduction to SVR4

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

Notes on Compilers
Depending on what you're used to, compiling programs in an SVR4 environment may require you to read the compiler documentation again. Because SVR4 provides ANSI C compliance in its include files, it is generally desirable to use the C compiler in an ANSI C mode. Furthermore, since the main goal of SVR4 is to promote interoperability through standards compliance, it is desirable to enable standards-compliance whenever you're developing a new program.
This section briefly discusses the compilers available for each of the operating systems described in this book. The examples in the book have been compiled and tested using all of these compilers.
The HP-UX 10.x Compiler
HP-UX 10.x uses an unbundled ANSI C compliant compiler called cc. The compiler accepts a plethora of options, most of which are not of interest to us here. However, there is one option that is important. The compiler allows you to select the degree of conformance to the ANSI C standard by using the -Ax option, where x is one of the following options:
a
Pure ANSI C
c
K&R C
e
ANSI C with POSIX and UNIX extensions
The examples in this book have been compiled and tested using the -Ae option to the compiler.
The IRIX 5.x Compiler
IRIX 5.x ships with an ANSI C compliant compiler called cc. The compiler accepts a number of options, most of which are not of interest in this book. However, the option that controls the language features supported by the compiler is important, and is described as follows:
-ansi
Pure ANSI C
-ansiposix
ANSI C plus the definition of the _POSIX_SOURCE constant; this enables the inclusion of function prototypes for POSIX-defined functions
-cckr
K&R C, with some ANSI C extensions such as function prototypes and the void type
-xansi
ANSI C with POSIX and UNIX extensions. This is the default mode of the compiler
The examples in this book have been compiled and tested using the -xansi mode of the compiler.
The Solaris 2.x Compiler
Solaris 2.x does not ship with a compiler; you must  purchase it as a separate, unbundled product called SPARCompiler C, a commercial C compiler offered by SunSoft, a subsidiary of Sun Microsystems. SPARCompiler C is available either by itself or as part of a package called SPARCworks that includes a source-code debugger and other software. SPARCompiler C is fully compliant with the ANSI C standard; it also accepts programs written in the older dialect of the language described by Kernighan and Ritchie.
SPARCompiler C offers a plethora of command-line options, almost all of which are beyond the scope of this book. However, there is one option that is important. SPARCompiler C allows you to select the degree of conformance to the ANSI C standard by using the -Ax option, where x is one of the following options:
a
ANSI C with “Sun C” compatibility extensions and semantic changes required by ANSI C. In this mode, the compiler accepts both K&R C and ANSI C constructs. When it encounters a construct that has different semantics under K&R and ANSI C, it issues a warning and then interprets the construct in accordance with the ANSI C definition.
c
Fully conformant ANSI C, without “Sun C” compatibility extensions. In this mode, the compiler rejects constructs that are not ANSI C. Header files do not declare certain functions, or define certain macros, that are not required by the ANSI C standard.
s
“Sun C.” In this mode, the compiler functions essentially as a K&R C compiler. However, it issues warnings about all constructs it encounters that have differing behavior between ANSI C and K&R C.
t
ANSI C with “Sun C” compatibility extensions, but not semantic changes required by ANSI C. In this mode, the compiler accepts both K&R C and ANSI C constructs. When it encounters a construct that has different semantics under K&R and ANSI C, it issues a warning and then interprets the construct in accordance with the K&R C definition.
The examples in this book have been compiled and tested using the -Xa option of SPARCompiler C.
The GNU C Compiler
The GNU C Compiler is distributed by the Free Software Foundation, and is available without charge, in source or binary form, to anyone who wants it. You can obtain it using anonymous FTP from numerous hosts on the Internet, from a tape from the Free Software Foundation, or from companies such as Cygnus Support. GNU C is available for all three of the operating systems described in this book; it is particularly popular on Solaris 2.x, because that system does not ship with a C compiler of its own.
GNU C is fully compliant with the ANSI C standard, and also accepts programs written in the older K&R dialect of the language.
GNU C accepts a profuse number of options, most of which are beyond the scope of this book. However, the options that let you select the degree of ANSI C conformance are important, and are described as follows:
-ansi
Enables support for all ANSI C programs. This turns off features of GNU C that are incompatible with ANSI C, and turns off predefined symbols such as sun and unix that allow you to identify the type of system that you are using. The -ansi option also predefines the macro __STRICT_ANSI__; some header files recognize this macro and do not declare certain functions or define certain macros that are not part of the ANSI C standard. This option does not cause rejection of valid non-ANSI programs, however; for that, the -pedantic option is also required.
-ansi -pedantic
Enables support for all ANSI C programs, and disables support for anything not specified in the ANSI C standard. Under this option, all warnings required by the ANSI C standard are issued, and any program that uses a forbidden extension is rejected. Valid ANSI C programs will compile with or without this option, however. Note that this option is not intended to verify a program as ANSI-compliant. It finds some non-ANSI constructs, but only those for which the ANSI standard requires a diagnostic.
-traditional
Attempts to support most of the aspects of K&R C. Although this isn't really a K&R mode of the compiler, you can compile most K&R C programs without changes by specifying this option. The option enables several old, undocumented preprocessor features that were never an official part of the language, but nevertheless came to be relied upon by many people. It also enables some features of K&R C that are not part of the ANSI C standard.
The examples in this book have been compiled and tested using the GNU C compiler without specifying any of the previous options.
 Note:Because the authors of the GNU C Compiler do not agree with the authors of SVR4 in the interpretation of the ANSI C standard's definition of the _ _STDC_ _ macro, you cannot use the GNU C Compiler with the normal SVR4 include files.
 GNU C protects itself from this problem by generating its own version of the system include files with the fixincludes command. The GNU C installation procedure runs this command automatically. However, when upgrading to a new version of the operating system, you must be sure to re-run fixincludes on the new system's include files, or compilation problems occur.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback