[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here HP C

HP C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index


va_arg

Returns the next item in the argument list.

Format

#include <stdarg.h> (ANSI C)

#include <varargs.h> (HP C EXTENSION)

type va_arg (va_list ap, type);


Arguments

ap

A variable list containing the next argument to be obtained.

type

A data type that is used to determine the size of the next item in the list. An argument list can contain items of varying sizes, but the calling routine must determine what type of argument is expected since it cannot be determined at run time.

Description

The va_arg function interprets the object at the address specified by the list incrementor according to type. If there is no corresponding argument, the behavior is undefined.

When using va_arg to write portable applications, include the <stdarg.h> header file (defined by the ANSI C standard), not the <varargs.h> header file, and use va_arg only in conjunction with other functions and macros defined in <stdarg.h> .

For an example of argument-list processing using the <stdarg.h> functions and definitions, see Example 3-6.


va_count

Returns the number of longwords (VAX ONLY) or quadwords (ALPHA ONLY) in the argument list.

Format

#include <stdarg.h> (ANSI C)

#include <varargs.h> (HP C EXTENSION)

void va_count (int count);


Argument

count

An integer variable name in which the number of longwords (VAX ONLY) or quadwords (ALPHA ONLY) is returned.

Description

The va_count macro places the number of longwords (VAX ONLY) or quadwords (ALPHA ONLY) in the argument list into count. The value returned in count is the number of longwords (VAX ONLY) or quadwords (ALPHA ONLY) in the function argument block not counting the count field itself.

If the argument list contains items whose storage requirements are a longword (VAX ONLY) or quadword (ALPHA ONLY) of memory or less, the number in the count argument is also the number of arguments. However, if the argument list contains items that are longer than a longword (VAX ONLY) or a quadword (ALPHA ONLY), count must be interpreted to obtain the number of arguments. Because a double is 8 bytes, it occupies two argument-list positions on OpenVMS VAX systems, and one argument-list position on OpenVMS Alpha systems.

The va_count macro is specific to HP C for OpenVMS Systems and is not portable.


va_end

Finishes the <varargs.h> or <stdarg.h> session.

Format

#include <stdarg.h> (ANSI C)

#include <varargs.h> (HP C EXTENSION)

void va_end (va_list ap);


Argument

ap

The object used to traverse the argument list length. You must declare and use the argument ap as shown in this format section.

Description

You can execute multiple traversals of the argument list, each delimited by va_start ... va_end . The va_end function sets ap equal to NULL.

When using this function to write portable applications, include the <stdarg.h> header file (defined by the ANSI C standard), not the <varargs.h> header file, and use va_end only in conjunction with other routines defined in <stdarg.h> .

For an example of argument-list processing using the <stdarg.h> functions and definitions, see Example 3-6.


va_start, va_start_1

Used for initializing a variable to the beginning of the argument list.

Format

#include <varargs.h> (HP C EXTENSION)

void va_start (va_list ap);

void va_start_1 (va_list ap, int offset);


Arguments

ap

An object pointer. You must declare and use the argument ap as shown in the format section.

offset

The number of bytes by which ap is to be incremented so that it points to a subsequent argument within the list (that is, not to the start of the argument list). Using a nonzero offset can initialize ap to the address of the first of the optional arguments that follow a number of fixed arguments.

Description

The va_start macro initializes the variable ap to the beginning of the argument list.

The va_start_1 macro initializes ap to the address of an argument that is preceded by a known number of defined arguments. The printf function is an example of a HP C RTL function that contains a variable-length argument list offset from the beginning of the entire argument list. The variable-length argument list is offset by the address of the formatting string.

When determining the value of the offset argument used in va_start_1 , the implications of the OpenVMS calling standard must be considered.

On OpenVMS VAX, most argument items are a longword. For example, OpenVMS VAX arguments of types char and short use a full longword of memory when they are present in argument lists. However, OpenVMS VAX arguments of type float use two longwords because they are converted to type double .

On OpenVMS Alpha, each argument item is a quadword.

Note

When accessing argument lists, especially those passed to a subroutine (written in C) by a program written in another programming language, consider the implications of the OpenVMS calling standard. For more information about the OpenVMS calling standard, see the HP C User's Guide for OpenVMS Systems or the OpenVMS Calling Standard.

The preceding version of va_start and va_start_1 is specific to the HP C RTL, and is not portable.

The following syntax describes the va_start macro in the <stdarg.h> header file, as defined in the ANSI C standard:


Format

#include <stdarg.h> (ANSI C)

void va_start (va_list ap, parmN);


Arguments

ap

An object pointer. You must declare and use the argument ap as shown in the format section.

parmN

The name of the last of the known fixed arguments.

Description

The pointer ap is initialized to point to the first of the optional arguments that follow parmN in the argument list.

Always use this version of va_start in conjunction with functions that are declared and defined with function prototypes. Also use this version of va_start to write portable programs.

For an example of argument-list processing using the <stdarg.h> functions and definitions, see Example 3-6.


vfork

Creates an independent child process. This function is nonreentrant.

Format

#include <unistd.h>

int vfork (void); (_DECC_V4_SOURCE)

pid_t vfork (void); (NOT _DECC_V4_SOURCE)


Description

The vfork function provided by HP C for OpenVMS Systems differs from the fork function provided by other C implementations. Table REF-12 shows the two major differences.

Table REF-12 The vfork and fork Functions
The vfork Function The fork Function
Used with the exec functions. Can be used without an exec function for asynchronous processing.
Creates an independent child
process that shares some of
the parent's characteristics.
Creates an exact duplicate of the parent process that branches at the point where vfork is called, as if the parent and the child are the same process at different stages of execution.

The vfork function provides the setup necessary for a subsequent call to an exec function. Although no process is created by vfork , it performs the following steps:

  • It saves the return address (the address of the vfork call) to be used later as the return address for the call to an exec function.
  • It saves the current context.
  • It returns the integer 0 the first time it is called (before the call to an exec function is made). After the corresponding exec function call is made, the exec function returns control to the parent process, at the point of the vfork call, and it returns the process ID of the child as the return value. Unless the exec function fails, control appears to return twice from vfork even though one call was made to vfork and one call was made to the exec function.

The behavior of the vfork function is similar to the behavior of the setjmp function. Both vfork and setjmp establish a return address for later use, both return the integer 0 when they are first called to set up this address, and both pass back the second return value as though it were returned by them rather than by their corresponding exec or longjmp function calls.

However, unlike setjmp , with vfork , all local automatic variables, even those with volatile-qualified type, can have indeterminate values if they are modified between the call to vfork and the corresponding call to an exec routine.


Return Values

0 Indicates successful creation of the context.
nonzero Indicates the process ID (PID) of the child process.
- 1 Indicates an error -- failure to create the child process.

vfprintf

Prints formatted output based on an argument list.

Format

#include <stdio.h>

int vfprintf (FILE *file_ptr, const char *format, va_list ap);


Arguments

file_ptr

A pointer to the file to which the output is directed.

format

A pointer to a string containing the format specification. For more information about format and conversion specifications and their corresponding arguments, see Chapter 2.

ap

A list of expressions whose resultant types correspond to the conversion specifications given in the format specifications.

Description

See also vprintf and vsprintf .

Return Values

x The number of bytes written.
Negative value Indicates an output error. The function sets errno . For a list of possible errno values set, see fprintf .

vfscanf

Reads formatted input based on an argument list.

Format

#include <stdio.h>

int vfscanf (FILE *file_ptr, const char *format, va_list ap);


Arguments

file_ptr

A pointer to the file that provides input text.

format

A pointer to a string containing the format specification.

ap

A list of expressions whose resultant types correspond to the conversion specifications given in the format specifications.

Description

The vfscanf function is the same as the fscanf function except that instead of being called with a variable number of arguments, it is called with an argument list that has been initialized by va_start (and possibly subsequent va_arg calls).

If no conversion specifications are given, you can omit the input pointers. Otherwise, the function calls must have exactly as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers.

Conversion specifications are matched to input sources in left-to-right order. Excess input pointers, if any, are ignored.

For more information about format and conversion specifications and their corresponding arguments, see Chapter 2.

This function returns the number of successfully matched and assigned input items.

See also vscanf and vsscanf .


Return Values

n The number of successfully matched and assigned input items.
EOF Indicates that the end-of-file was encountered or a read error occurred. If a read error occurs, the function sets errno to one of the following:
  • EILSEQ -- Invalid character detected.
  • EINVAL -- Insufficient arguments.
  • ENOMEM -- Not enough memory available for conversion.
  • ERANGE -- Floating-point calculations overflow.
  • EVMSERR -- Nontranslatable OpenVMS error. vaxc$errno contains the OpenVMS error code. This can indicate that conversion to a numeric value failed due to overflow.

The function can also set errno to the following as a result of errors returned from the I/O subsystem:

  • EBADF -- The file descriptor is not valid.
  • EIO -- I/O error.
  • ENXIO -- Device does not exist.
  • EPIPE -- Broken pipe.
  • EVMSERR -- Nontranslatable OpenVMS error. vaxc$errno contains the OpenVMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code.

vfwprintf

Writes output to the stream under control of the wide-character format string.

Format

#include <wchar.h>

int vfwprintf (FILE *stream, const wchar_t *format, va_list ap);


Arguments

stream

A file pointer.

format

A pointer to a wide-character string containing the format specifications. For more information about format and conversion specifications and their corresponding arguments, see Chapter 2.

ap

A variable list of the items needed for output.

Description

The vfwprintf function is equivalent to the fwprintf function, with the variable argument list replaced by the ap argument. Initialize ap with the va_start macro (and possibly with subsequent va_arg calls) from <stdarg.h> .

If the stream pointed to by stream has no orientation, vfwprintf makes the stream wide-oriented.

See also fwprintf .


Return Values

n The number of wide characters written.
Negative value Indicates an error. The function sets errno to one of the following:
  • EILSEQ -- Invalid character detected.
  • EINVAL -- Insufficient arguments.
  • ENOMEM -- Not enough memory available for conversion.
  • ERANGE -- Floating-point calculations overflow.
  • EVMSERR -- Nontranslatable OpenVMS error. vaxc$errno contains the OpenVMS error code. This might indicate that conversion to a numeric value failed because of overflow.

The function can also set errno to the following as a result of errors returned from the I/O subsystem:

  • EBADF -- The file descriptor is not valid.
  • EIO -- I/O error.
  • ENOSPC -- No free space on the device containing the file.
  • ENXIO -- Device does not exist.
  • EPIPE -- Broken pipe.
  • ESPIPE -- Illegal seek in a file opened for append.
  • EVMSERR -- Nontranslatable OpenVMS error. vaxc$errno contains the OpenVMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code.

Examples

The following example shows the use of the vfwprintf function in a general error reporting routine:


 #include <stdarg.h>
 #include <stdio.h>
 #include <wchar.h>

 void error(char *function_name, wchar_t *format, ...);
 {
    va_list args;

    va_start(args, format);
    /* print out name of function causing error */
    fwprintf(stderr, L"ERROR in %s: ", function_name);
    /* print out remainder of message */
    vfwprintf(stderr, format, args);
    va_end(args);
 }

vfwscanf

Reads input from the stream under control of a wide-character format string.

Format

#include <wchar.h>

int vfwscanf (FILE *stream, const wchar_t *format, va_list ap);


Arguments

stream

A file pointer.

format

A pointer to a wide-character string containing the format specifications.

ap

A list of expressions whose resultant types correspond to the conversion specifications given in the format specifications.

Description

The vfwscanf function is equivalent to the fwscanf function, except that instead of being called with a variable number of arguments, it is called with an argument list (ap) that has been initialized by va_start (and possibly with subsequent va_arg calls).

If the stream pointed to by stream has no orientation, vfwscanf makes the stream wide-oriented.

For more information about format and conversion specifications and their corresponding arguments, see Chapter 2.


Return Values

n The number of successfully matched and assigned wide-character input items.
EOF Indicates that a read error occurred before any conversion. The function sets errno . For a list of the values set by this function, see vfscanf .

vprintf

Prints formatted output based on an argument list.

This function is the same as the printf function except that instead of being called with a variable number of arguments, it is called with an argument list that has been initialized by the va_start macro (and possibly with subsequent va_arg calls) from <stdarg.h> .


Format

#include <stdio.h>

int vprintf (const char *format, va_list ap);


Arguments

format

A pointer to the string containing the format specification. For more information about format and conversion specifications and their corresponding arguments, see Chapter 2.

ap

A variable list of the items needed for output.

Description

See the vfprintf and vsprintf functions.

Return Values

x The number of bytes written.
Negative value Indicates an output error. The function sets errno . For a list of possible errno values set, see fprintf .


Previous Next Contents Index