Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

58 UNIX Standardization and Implementations Chapter 2


This causes the featuretest macro to be defined beforeany header files areincluded by
the C program. If we want to use only the POSIX.1 definitions, we can also set the first
line of a source file to
#define _POSIX_C_SOURCE 200809L
To enable the XSI option of Version 4 of the Single UNIX Specification, we need to
define the constant_XOPEN_SOURCEto be 700. Besides enabling the XSI option, this
has the same effect as defining_POSIX_C_SOURCEto be 200809L as far as POSIX.1
functionality is concerned.
The Single UNIX Specification defines thec99utility as the interface to the C
compilation environment. With it we can compile a file as follows:
c99 -D_XOPEN_SOURCE=700 file.c -o file
To enable the 1999 ISO C extensions in thegccCcompiler, we use the-std=c99
option, as in
gcc -D_XOPEN_SOURCE=700 -std=c99 file.c -o file

2.8 PrimitiveSystem Data Types


Historically,certain C data types have been associated with certain UNIX system
variables. For example, major and minor device numbers have historically been stored
in a 16-bit short integer,with 8 bits for the major device number and 8 bits for the minor
device number.But many larger systems need morethan 256 values for these device
numbers, so a different technique is needed. (Indeed, the 32-bit version of Solaris uses
32 bits for the device number: 14 bits for the major and 18 bits for the minor.)
The header<sys/types.h>defines some implementation-dependent data types,
called theprimitive system data types.More of these data types aredefined in other
headers as well. These data types aredefined in the headers with the Ctypedef
facility.Most end in_t.Figure2.21 lists many of the primitive system data types that
we’ll encounter in this text.
By defining these data types this way, we do not build into our programs
implementation details that can change from one system to another.Wedescribe what
each of these data types is used for when we encounter them later in the text.

2.9 Differences Between Standards


All in all, these various standards fit together nicely.Our main concern is any
differences between the ISO C standardand POSIX.1, since the Base Specifications of
the Single UNIX Specification and POSIX.1 areone and the same. Conflicts are
unintended, but if they should arise, POSIX.1 defers to the ISO C standard. However,
thereare some differences.
ISO C defines the functionclockto return the amount of CPU time used by a
process. The value returned is aclock_tvalue, but ISO C doesn’t specify its units. To
Free download pdf