United States    
COMPAQ STORE | PRODUCTS |
SERVICES | SUPPORT | CONTACT US | SEARCH
Compaq C

Compaq C
Language Reference Manual


Previous Contents Index

double log10(double x);

Returns the base-ten logarithm of x. A domain error occurs if x is negative. A range error may occur if x is 0.

double modf(double value, double *iptr);

Breaks the argument value into integral and fractional parts, each of which has the same sign as the argument. The modf function returns the signed fractional part and stores the integral part as a double in the object pointed to by iptr.

Power Functions

double pow(double x, double y);

Returns the value xy. A domain error occurs if x is negative and y is not an integral value. A domain error occurs if the result cannot be represented when x is 0 and y is less than or equal to 0. A range error may occur.

double sqrt(double x);

Returns the nonnegative square root of x. A domain error occurs if x is negative.

Nearest Integer, Absolute Value, and Remainder Functions

double ceil(double x);

Returns the smallest integral value not less than x.

double fabs(double x);

Returns the absolute value of a floating-point number x.

double floor(double x);

Returns the largest integral value not greater than x.

double fmod(double x, double y);

Computes the floating-point remainder of x/y. The fmod function returns the value x -- i * y, for some integer i such that if y is nonzero, the result has the same sign as x and magnitude less than the magnitude of y. The function returns 0 if y is 0.

9.7 Nonlocal Jumps (<setjmp.h>)

The <setjmp.h> header file contains declarations that provide a way to avoid the normal function call and return sequence, typically to permit an intermediate return from a nested function call.

Macro

int setjmp(jmp_buf env)

Sets up the local jmp_buf buffer and initializes it for the jump (the jump itself is performed with longjmp .) This macro saves the program's calling environment in the environment buffer specified by the env argument for later use by the longjmp function. If the return is from a direct invocation, setjmp returns 0. If the return is from a call to longjmp , setjmp returns a nonzero value.

Type

jmp_buf

An array type suitable for holding the information needed to restore a calling environment.

Function

Restores the context of the environment buffer env that was saved by invocation of the setjmp function in the same invocation of the program. The longjmp function does not work if called from a nested signal handler; the result is undefined.
The value specified by value is passed from longjmp to setjmp . After longjmp is completed, program execution continues as if the corresponding invocation of setjmp had just returned value. If value is passed to setjmp as 0, it is converted to 1.

9.8 Signal Handling (<signal.h>)

The <signal.h> header file declares a type and two functions and defines several macros for handling exception conditions that might be reported during program execution.

Type

sig_atomic_t

The integral type of an object that can be accessed as an atomic entity, even in the presence of asynchronous interrupts.

Macros


SIG_DFL
SIG_ERR
SIG_IGN

Expand to constant expressions with distinct values that have a type compatible with the second argument to, and the return value of, the signal function, and whose value compares unequal to the address of any declarable function.

Functions

void (*signal(int sig, void (*handler) (int))) (int);

Determines how subsequent signals are handled. Signals are handled in the following way:
  1. If the value of handler is SIG_DFL , default handling of that signal occurs.
  2. If the value of handler is SIG_IGN , the signal is ignored.
  3. Otherwise, when that signal occurs, a function pointed to by handler is called with the argument of the type of signal. Such a function is called a signal handler. Valid signals include:
    • SIGABRT---abnormal termination, such as from the abort function
    • SIGFPE---arithmetic error, such as zero divide or overflow
    • SIGILL---invalid function image, such as an invalid instruction
    • SIGINT---interactive attention, such as an interrupt
    • SIGSEGV---invalid access to storage, such as outside of memory limit
    • SIGTERM---termination request sent to the program

Any other signals are operating-system dependent.
If the request can be honored, the signal function returns the value of handler for the most recent call to signal for the specified signal sig . Otherwise, a value of SIG_ERR is returned and an implementation-defined positive value is stored in errno .

int raise(int sig);

Sends the signal sig to the executing program. The raise function returns 0 if successful and nonzero if unsuccessful.

9.9 Variable Arguments (<stdarg.h>)

The <stdarg.h> header file declares a type and defines three macros for advancing through a list of function arguments of varying number and type.

Type

va_list

A type suitable for holding information needed by the macros va_start , va_arg , and va_end .
To access varying arguments, the called function must declare an object (referred to as ap in this section) that has the type va_list :


va_list ap; 

The object ap can be passed as an argument to another function. If that function invokes the va_arg macro with parameter ap, the value of ap in the calling function is indeterminate and is passed to the va_end macro before any further reference to ap.

Macros

void va_start(va_list ap, parmN);

Initializes ap for subsequent use by va_arg and va_end . The va_start macro must be invoked before any access to the unnamed arguments.
The parameter parmN is the identifier of the rightmost parameter in the variable parameter list of the function definition. If parmN is declared with the register storage class, with a function or array type, or with a type that is not compatible with the type that results after application of the default arguments promotions, the behavior is undefined. The va_start macro returns no value.

type va_arg(va_list ap, type);

Expands to an expression that has the type and value of the next argument in the call. The parameter ap is the same as the va_list ap that was initialized by va_start . Each invocation of va_arg modifies ap so that the values of successive arguments are returned in turn. The parameter type is a type name specified such that the type of a pointer to an object that has the specified type can be obtained by postfixing an asterisk (*) to type. The behavior is undefined if there is no actual next argument, or if type is not compatible with the type of the next actual argument (as promoted according to the default argument promotions).
The first invocation of va_arg after that of va_start returns the value of the argument after that specified by parmN. Successive invocations return the values of the remaining arguments in turn.

void va_end(va_list ap);

Facilitates a normal return from the function whose variable argument list was referred to by the expansion of va_start that initialized the va_list ap object. The va_end macro can modify ap so that it can no longer be used (without an intervening invocation of va_start ). If there is no corresponding invocation of va_start or if va_end is not invoked before the return, the behavior is undefined. The va_end macro returns no value.

9.10 Common Definitions (<stddef.h>)

The <stddef.h> header file defines several types and macros, some of which are also defined in other header files.

Types

ptrdiff

A signed integral type of the result of subtracting two pointers.

size_t

An unsigned integral type of the result of the sizeof operator.

wchar_t

An integral type whose range of values can represent distinct codes for all members of the largest extended character set specified among the supported locales.

Macros

NULL

Expands to an implementation-defined null pointer constant.

offsetof(type, member-designator)

Expands to an integral constant expression that has type size_t and a value that is the offset, in bytes, to the structure member (specified by member-designator) from the beginning of its structure (specified by type). The member-designator is such that the expression &(t.member-designator) evaluates to an address constant given the following:


static type t; 

If the specified member is a bit field, the behavior is undefined.

9.11 Standard Input/Output (<stdio.h>)

The <stdio.h> header file declares three types, several macros, and many functions for performing text input and output. A text stream consists of a sequence of lines; each line ends with a new-line character.

Types

size_t

An unsigned integral type of the result of the sizeof operator.

FILE

An object type capable of recording all the information needed to control a data stream, including its file-position indicator, a pointer to its associated buffer (if any), an error indicator that records whether a read/write error occurred, and an end-of-file indicator that records whether the end of the file has been reached.

fpos_t

An object capable of recording all the information needed to uniquely specify every position within a file.

Macros

NULL

Expands to an implementation-defined null pointer constant.

_IOFBF
_IOLBF
_IONBF

Expand to integral constant expressions with distinct values, suitable for use as the third argument to the setvbuf function.

BUFFSIZ

Expands to an integral constant expression, which is the size of the buffer used by the setbuf function.

EOF

Expands to a negative integral constant expression that is returned by several functions to indicate end-of-file.

FOPEN_MAX

Expands to an integral constant expression that is the minimum number of files that the Compaq C compiler for your system guarantees can be open simultaneously.

FILENAME_MAX

Expands to an integral constant expression that is the size needed for an array of char large enough to hold the longest file name string that the Compaq C compiler for your system guarantees can be opened.

L_tmpnam

Expands to an integral constant expression that is the size needed for an array of char large enough to hold a temporary file name string generated by the tmpnam function.

SEEK_CUR
SEEK_END
SEEK_SET

Expand to integral constant expressions with distinct values; suitable for use as the third argument to the fseek function.

TMP_MAX

Expands to an integral constant expression that is the minimum number of unique file names that can be generated by the tmpnam function.

stderr
stdin
stdout

Expressions of type pointer to FILE that point to the FILE objects associated, respectively, with the standard error, input, and output streams.

File Operation Functions

int remove(const char *filename);

Makes the file whose name is pointed to by filename no longer accessible by that name. Any subsequent attempt to open that file using that name will fail. The remove function returns 0 if the operation succeeds, nonzero if it fails. If the file is open, the behavior of this function is implementation-defined.

int rename(const char *old, const char *new);

Renames the file from the name pointed to by old to the name pointed to by new. The file is no longer accessible by the old name. The rename function returns 0 if the operation succeeds, nonzero if it fails (in which case the file, if it existed, is still known by its original name). If the new file exists before rename is called, the behavior of this function is implementation-defined.

FILE *tmpfile(void);

Creates a temporary binary file that is automatically removed when it is closed or when program execution ends. If execution ends abnormally, whether an open temporary file is removed is implementation-dependent. The file is opened for update with wb+ mode (see Table 9-1). The tmpfile function returns a pointer to the stream of the file that it created. If the file cannot be created, tmpfile returns a null pointer.

FILE *tmpnam(void);

Generates a valid file name that is different than the name of an existing file. Each call to tmpnam , up to TMP_MAX times, generates a different name. If tmpnam is called more than TMP_MAX times, the behavior is implementation-defined.
If the argument is a null pointer, the tmpnam function leaves its result in an internal static object and returns a pointer to that object. Subsequent calls to tmpnam can modify the same object. If the argument is not a null pointer, it is assumed to point to an array of at least L_tmpnam chars . The tmpnam function writes its result into that array and returns the argument as its value.

File Access Functions

int fclose(FILE *stream);

Flushes the stream pointed to by stream and closes the associated file. Any unwritten buffered data for the stream is delivered to the host environment to be written to the file. Any unread buffered data is discarded. The stream is disassociated from the file. If the associated buffer was automatically allocated, it is deallocated. The fclose function returns 0 if the stream was successfully closed, or it returns EOF if any errors are detected.

int fflush(FILE *stream);

If stream points to an output stream or an update stream in which the most recent operation was not input, the fflush function delivers any unwritten data to the host environment to be written to the file. Otherwise, the behavior is undefined. If stream is a null pointer, fflush flushes all output or update streams in which the most recent operation was not input. The fflush function returns 0 if the operation is successful, or it returns EOF if a write error occurs.

FILE *fopen(const char *filename, const char *mode);

Opens the file pointed to by filename and associates a stream with it. The argument mode points to a string beginning with one of the character sequences listed in Table 9-1. Additional characters can follow these sequences.

Table 9-1 File Modes
Mode Description
r open text file for reading
w truncate to zero length or create text file for writing
a append; open or create text file for writing at end-of-file
rb open binary file for reading
wb truncate to zero length or create binary file for writing
ab append; open or create binary file for writing at end-of-file
r+ open text file for update (reading and writing)
w+ truncate to zero length or create text file for update
a+ append; open or create text file for update, writing at end-of-file
r+b or rb+ open binary file for update (reading and writing)
w+b or wb+ truncate to zero length or create binary file for update
a+b or ab+ append; open or create binary file for update, writing at end-of-file

The fopen function returns a pointer to the object controlling the stream. If the open operation fails, fopen returns a null pointer.

FILE *freopen(const char *filename, const char *mode, FILE *stream);

Opens the file pointed to by filename and associates the stream pointed to by stream with it. The mode argument is used in the same way as with the fopen function. The freopen function first tries to close any file associated with the specified stream. Failure to close the file successfully is ignored. The error and end-of-file indicators for the stream are cleared.
The primary use of freopen is to change the file associated with a standard text stream ( stderr , stdin , or stdout ), because those identifiers need not be modifiable lvalues to which the value returned by the fopen function can be assigned.
The freopen function returns a pointer to the object controlling the stream. If the open operation fails, freopen returns a null pointer.

void setbuf(FILE *stream, char *buf);

Except that it returns no value, the setbuf function is equivalent to the setvbuf function invoked with the values _IOFBF for mode and BUFSIZ for size, or (if buf is a null pointer) with the value _IONBF for mode.

int setvbuf(FILE *stream, char *buf, int mode size_t size);

Associates a buffer with an input or an output file. The setvbuf function can be used only after the stream pointed to by stream has been associated with an open file and before any other operation is performed on the stream. The argument mode determines how stream is to be buffered:
If buf is not a null pointer, the array it points to can be used instead of a buffer allocated by the setvbuf function. The size of the array is specified by size. The contents of the array at any time are indeterminate. The setvbuf function returns 0 if successful, or nonzero if an invalid value is specified for mode or if the request cannot be honored.


Previous Next Contents Index
  

1.800.AT.COMPAQ

privacy and legal statement