Kernel header files contain ANSI function prototypes. Code
written in ANSI C benefit from the compile time checking of argument
types and return types that are specified by function prototypes.
Summary of Change |
 |
Kernel header files are included by code written in K&R
C (compatibility mode), as well as code written in ANSI C. Compile
time errors will result if ANSI function prototypes are made visible
to K&R C code; the compatibility mode C compiler does not
recognize ANSI function prototypes. To prevent such errors, header
files use the __()
macro to declare function prototypes. The macro is defined in the
header file stdsyms.h
as follows:
#if defined(_PROTOTYPES) #define __(arg) arg #else #define __(arg) () #endif |
To illustrate the usage of the __()
macro, consider the function prototype of printf():
extern int printf __((const char *fmt, ...)); |
This is equivalent to declaring printf()
as:
#ifdef _PROTOTYPES extern int printf (const char *fmt, ...); #else extern int printf (); #endif |
Use of the __()
macro can also be found in structure declarations that contain function
pointers. Consider the drv_ops
structure in the header file conf.h:
typedef struct drv_ops { int (*d_open) __((dev_t dev, int oflags, intptr_t dummy, int mode)); . . . } drv_ops_t; |
Many, but not all, header files contain ANSI function prototypes;
many of these use the __()
macro. ANSI function prototypes of many HP-UX kernel interfaces
have been incorporated in header files appropriate to the kernel
interface. For example, the following HP-UX kernel interfaces that
specify the buf
structure are declared in the header file buf.h:
extern void biodone __((struct buf *)); extern int biowait __((struct buf *)); |
A new header file, kern_svcs.h,
has been added to HP-UX 10.30. This header file contains ANSI function
prototypes of commonly used HP-UX kernel interfaces for which an
appropriate header file does not exist.
The kern_svcs.h
header file defines some function prototypes, such as formal descriptions
for function types and arguments. This header file is included by
selected kernel header files so that other headers do not need to
include it. For example, wsio.h
is a key header file for WSIO drivers and it includes kern_svcs.h
for the benefit of all WSIO drivers. Drivers that include wsio.h
are, therefore, not required to explicitly include kern_svcs.h.
Impact |
 |
Code that is compiled with _KERNEL
defined is impacted because function prototypes in the kernel header
files are made visible to the compiler via #ifdef _KERNEL.
Only code intended to be linked with the kernel should define _KERNEL.
The C compiler displays warning messages where arguments passed
to, or use of values returned from, functions are not compatible
with the specified function prototypes. In some cases, compiler
errors might be generated. You are expected to correct code that
result in compiler-generated warnings and errors.