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

Compaq C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index


VAXC$CRTL_INIT

Allows you to call the Compaq C RTL from other languages or to use the Compaq C RTL when your main function is not in C. It initializes the run-time environment and establishes both an exit and condition handler. vaxc$crtl_init is a synonym for decc$crtl_init . Either name invokes the same routine.

Format

#include <signal.h>

void VAXC$CRTL_INIT();


Description

The following example shows a Pascal program that calls the Compaq C RTL using the vaxc$crtl_init function:

On OpenVMS VAX systems:


$ PASCAL EXAMPLE 
$ LINK EXAMPLE,SYS$LIBRARY:DECCRTL/LIB 
$ TY EXAMPLE.PAS 
PROGRAM TESTC(input, output); 
PROCEDURE VAXC$CRTL_INIT; extern; 
BEGIN 
   VAXC$CRTL_INIT; 
END 
$ 

On OpenVMS Alpha systems:


$ PASCAL EXAMPLE 
$ LINK EXAMPLE,SYS$LIBRARY:VAXCRTL/LIB  
$ TY EXAMPLE.PAS 
PROGRAM TESTC(input, output); 
PROCEDURE VAXC$CRTL_INIT; extern; 
BEGIN 
   VAXC$CRTL_INIT; 
END 
$ 

A shareable image need only call this function if it contains a Compaq C function for signal handling, environment variables, I/O, exit handling, a default file protection mask, or if it is a child process that should inherit context.

Although many of the initialization activities are performed only once, decc$crtl_init can safely be called multiple times. On OpenVMS VAX systems, decc$crtl_init establishes the Compaq C RTL internal OpenVMS exception handler in the frame of the routine that calls decc$crtl_init each time decc$crtl_init is called.

At least one frame in the current call stack must have that handler established for OpenVMS exceptions to get mapped to UNIX signals.


VAXC$ESTABLISH

Used for establishing an OpenVMS exception handler for a particular routine. This function establishes a special Compaq C RTL exception handler in the routine that called it. This special handler catches all RTL-related exceptions that occur in later routines, and passes on all other exceptions to your handler.

Format

#include <signal.h>

void VAXC$ESTABLISH (unsigned int (*exception_handler)(void *sigarr, void *mecharr));


Arguments

exception_handler

The name of the function that you want to establish as an OpenVMS exception handler. You pass a pointer to this function as the parameter to VAXC$ESTABLISH.

sigarr

A pointer to the signal array.

mecharr

A pointer to the mechanism array.

Description

vaxc$establish must be used in place of LIB$ESTABLISH when programs use the Compaq C RTL routines setjmp or longjmp . See setjmp and longjmp , or sigsetjmp and siglongjmp in this section.

You can only invoke the vaxc$establish function from a Compaq C for OpenVMS function, because it relies on the allocation of data space on the run-time stack by the Compaq C compiler. Calling the OpenVMS system library routine LIB$ESTABLISH directly from a Compaq C function results in undefined behavior from the setjmp and longjmp functions.

To cause an OpenVMS exception to generate a UNIX style signal, user exception handlers must return SS$_RESIGNAL upon receiving any exception that they do not want to handle. Returning SS$_NORMAL prevents the generation of a UNIX style signal. UNIX signals are generated as if by an exception handler in the stack frame of the main C program. Not all OpenVMS exceptions correspond to UNIX signals. See Chapter 4 for more information on the interaction of OpenVMS exceptions and UNIX style signals.

Calling vaxc$establish with an argument of NULL cancels an existing handler in that routine.

Notes

  • On OpenVMS Alpha systems, VAXC$ESTABLISH is implemented as a compiler built-in function, not as a Compaq C RTL function. (ALPHA ONLY)
  • On OpenVMS VAX systems, programs compiled with /NAMES=AS_IS should link against SYS$LIBRARY:DECCRTL.OLB to resolve the name VAXC$ESTABLISH, whether or not the program is compiled with the /PREFIX_LIBRARY_ENTRIES switch. This is a restriction in the implementation. (VAX ONLY)

va_arg

Used for returning the next item in the argument list.

Format

#include <stdarg.h> (ANSI C)

#include <varargs.h> (DEC 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

This 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 Chapter 3, 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> (DEC 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

This function 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.

This function is specific to Compaq 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> (DEC 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 Chapter 3, Example 3-6.


va_start_1, va_start

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

Format

#include <varargs.h> (DEC 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 Compaq 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 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 Compaq 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 Compaq 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 Chapter 3, 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

This function provided by Compaq 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:

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 arg);


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.

arg

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

Description

See the vprintf and vsprintf functions in this section.

See Chapter 2 for information on format specifiers.


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 in this section.

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 arg);


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.

arg

A variable list of the items needed for output.

Description

This function is equivalent to the fwprintf function, with the variable argument list replaced by the arg argument. Initialize arg 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 in this section


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 VMS error. vaxc$errno contains the VMS 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 VMS error. vaxc$errno contains the VMS 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); 
 } 


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 arg);


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.

arg

A variable list of the items needed for output.

Description

See the vfprintf and vsprintf functions this section.

See Chapter 2 for information on format specifiers.


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 in this section.


Previous Next Contents Index
  

1.800.AT.COMPAQ

privacy and legal statement