Digital UNIX Diffs - vprintf(5) Digital UNIX Diffs - vprintf(5)NAME
vprintf, vfprintf, vsprintf - Print formatted output
LIBRARY
Standard C Library (libc.so, libc.a)
SYNOPSIS
#include <stdio.h> #include <stdarg.h>
int vprintf(
const char *format,
va_list printarg);
int vfprintf(
FILE *stream,
const char *format,
va_list printarg);
int vsprintf(
char *string,
const char *format,
va_list printarg);
PARAMETERS
Specifies a character string that contains two types of objects: Plain
characters, which are copied to the output stream. Conversion specifi‐
cations, each of which causes zero or more items to be fetched from the
stdarg parameter lists. Specifies the arguments to be printed. Speci‐
fies the output stream. Specifies the buffer to which output is
printed.
DIFFERENCESvms-vaxc(5): OpenVMS VAX C vs DEC C Differences
The ANSI C Standard padding rules for the vprintf(3) routines are dif‐
ferent than the VAX C RTL behavior. The following examples illustrate
the differences using printf(3):
Example VAX C RTL DEC C RTL
printf("%04.2d", 77); "0077" " 77"
printf("%6.4d", 77); " 77" " 0077" printf("%.2g",
9.876e+2); "9.88e+02" "9.9e+02"
The ANSI C Standard also requires that an empty precision value in a
vprintf(3) format specifier be treated as a zero precision. The VAX C
RTL ignores an empty precision value as shown in the following
printf(3) example.
Example VAX C RTL DEC C RTL
printf("%-.s", "hello"); "hello" ""
The DEC C RTL will not accept uppercase versions of the vprintf(3) for‐
mat specifiers. For example, the DEC C RTL will not accept "%D" as a
format specifier, whereas, the VAX C RTL accepts "%D" as a synonym for
the "%d" format specifier. The DEC C RTL prints the letter encoun‐
tered; for example, "%D" produces the letter "D" in the output stream
rather than being processed as an output source.
ultrix-system(5): DEC ULTRIX Operating System Differences
On Digital UNIX, the vprintf(3) functions do not support the use of the
%D parameter for reading long numbers in decimal format as they do on
DEC ULTRIX. Instead, use the %d or %ld parameter in your print func‐
tions.
In Digital UNIX the vprintf(3) functions returns the number of dis‐
playable characters in the output (not necessarily the number of bytes)
for a success and a negative number for a failure. The value
vsprintf(3) returns for success does not include the terminating '\0'
character. In DEC ULTRIX, vprintf(3) and vfprintf(3) return zero for
success and EOF for failure. The DEC ULTRIX vsprintf(3) function
returns its first argument for success and end-of-file (EOF) for fail‐
ure.
alpha-32bits(5): 32 vs 64 bit Differences
When using the vprintf() function for long types, you use the length
modifier l (lower-case letter L) with the d, i, o, u, x, and X conver‐
sion characters to specify assignment of type long or unsigned long.
For example, when printing a long as a signed decimal, use %ld instead
of %d. When printing a long as an unsigned decimal, use %lu instead of
%u. If you omit the length modifier, the type is assumed to be int, or
unsigned int, depending on the conversion character. In this case, the
long types are converted to the smaller int types and information might
be lost.
When printing a pointer, use %p. If you want to print the pointer as a
specific representation, the pointer should be cast to an appropriate
integer type long prior to using the desired format specifier. For
example to print a pointer as a long unsigned decimal number, use %lu
as shown in this printf(3) example:
char *p;
printf ( "%lp = %lu\n", (void *) &p, (long) p);
As a rule, to print an integer of arbitrary size, cast the integer to
long or unsigned long, and use the %ld (unsigned long>>) conversion
character. For example:
printf ("%ld\n", (long)num);
EXAMPLES
#include <stdio.h> #include <stdarg.h> void error(char *funct, char
*format, ... ) {
va_list args;
/*
** Display the name of the function that called error
*/
fprintf(stderr, "ERROR in %s: ", funct);
/*
** Display the remainder of the message
*/
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
abort(); } void main() {
int *ptr;
int bytes = 0;
/*
** Malloc Memory
*/
bytes = bytes * sizeof(int);
ptr = (int*) malloc( bytes );
if (ptr == NULL)
{
error("malloc()", "Tried to allocate %ld bytes. (ptr: %p =
%ld)\n", (long) bytes, (void *) &ptr, (long)
ptr);
}
else
{
printf("malloc: Successful\n");
} }
RELATED INFORMATION
Functions: vprintf(3), vfprintf(3), vsprintf(3), printf(5)CATEGORY INDEXvms-vaxc(5), ultrix-system(5), alpha-32bits(5)
delim off
Digital UNIX Diffs - vprintf(5)