Sponsored Content
Top Forums Programming Internals of the printf function? Post 302418214 by Corona688 on Monday 3rd of May 2010 02:08:11 PM
Old 05-03-2010
Se 'man stdarg' for info on how it handles varying numbers of arguments.
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

on unix internals

will anybody tell me how can i access all the fields of process table .if there is any structure and a system call please specify . (1 Reply)
Discussion started by: vish_shan
1 Replies

2. HP-UX

HP-UX Internals Book

. (2 Replies)
Discussion started by: Driver
2 Replies

3. Shell Programming and Scripting

How to print a % within a printf() function using awk

Here is the code I'm using { printf("%11d %4.2f\% %4.2f\%\n", $1,$2,$3); } I want the output to look something like 1235415234 12.24% 52.46% Instead it looks something like 319203842 42.27\%4.2f\% How do I just print a "%" without awk or printf thinking I'm trying to do... (1 Reply)
Discussion started by: Awanka
1 Replies

4. Programming

why printf() function don't go work?

I use FreeBSD,and use signal,like follows: signal(SIGHUP,sig_hup); signal(SIGIO,sig_io); when I run call following code,it can run,but I find a puzzled question,it should print some information,such as printf("execute main()") will print execute main(),but in fact,printf fuction print... (2 Replies)
Discussion started by: konvalo
2 Replies

5. Linux

Kernel internals for ARM

Hi, Does anybody have a good pointer on Linux kernel internals for ARM architecture? I can locate plenty for x86 but since ARM is RISC I think there would be subtle changes. So if somebody has a knowledge of good document on Linux Kernel internals for ARM or even a comparative study of kernel on... (0 Replies)
Discussion started by: Rakesh Ranjan
0 Replies

6. Programming

Need more info on internals of c compilers

Hello Gurus, i am ok with the concepts of c language but i would like to know more about the internals of c with respect to the compilers what happens when we say gcc filename.c the a.out will get created(what actaully compiler does to the code inaddition to generating object code) ... (5 Replies)
Discussion started by: MrUser
5 Replies

7. UNIX for Dummies Questions & Answers

printf function

#include<stdio.h> int counter; int fibonacci(int n) { counter += 1; if ( n <= 2 ) return 1; else return fibonacci(n-1) + fibonacci(n-2); } int main(void) { int i; int sum ; for( i = 1 ; i<= 10; i++) { counter = 0; sum... (1 Reply)
Discussion started by: vincent__tse
1 Replies

8. Programming

How access a specific memory portion through printf() function????

Hi friends, Hope everyone is doing well. Please have a look at this simple program, you will figure out what I want. #include <stdio.h> int main() { printf("Enter an integer!\n"); scanf( "%d", 134511890 ); // Valid address on my computer printf( "%d\n", ???? ); return 0; } ... (3 Replies)
Discussion started by: gabam
3 Replies

9. UNIX for Advanced & Expert Users

GDB Breakpoint Internals

When we put a breakpoint using gcc then what all things happen internally and how the gdb using break is able to pause the execution of process( instead of killing it ) and later on resume the process execution? (0 Replies)
Discussion started by: rupeshkp728
0 Replies

10. What is on Your Mind?

How to switch from SVR4/BSD internals to Linux internals?

Hello, Long-time Unix hacker here - I've worked on four variants of the kernel prior to the introduction of Linux. In my spare time, I've written Linux (Ubuntu) device drivers, kernel modules, cross-compiled, and built the kernel. I'd like to do Linux internals/device drivers as a day job,... (1 Reply)
Discussion started by: OriginalVersion
1 Replies
STDARG(3)						   BSD Library Functions Manual 						 STDARG(3)

NAME
stdarg, va_arg, va_copy, va_end, va_start -- variable argument lists SYNOPSIS
#include <stdarg.h> void va_start(va_list ap, last); type va_arg(va_list ap, type); void va_copy(va_list dest, va_list src); void va_end(va_list ap); DESCRIPTION
A function may be called with a varying number of arguments of varying types. The include file <stdarg.h> declares a type (va_list) and defines three macros for stepping through a list of arguments whose number and types are not known to the called function. The called function must declare an object of type va_list which is used by the macros va_start(), va_arg(), va_end(), and, optionally, va_copy(). The va_start() macro initializes ap for subsequent use by va_arg(), va_copy() and va_end(), and must be called first. The parameter last is the name of the last parameter before the variable argument list, i.e. the last parameter of which the calling function knows the type. Because the address of this parameter is used in the va_start() macro, it should not be declared as a register variable, or as a function or an array type. The va_start() macro returns no value. The va_arg() macro expands to an expression that has the type and value of the next argument in the call. The parameter ap is the va_list ap initialized by va_start(). Each call to va_arg() modifies ap so that the next call returns the next argument. The parameter type is a type name specified so that the type of a pointer to an object that has the specified type can be obtained simply by adding a * to type. If there is no next argument, or if type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), random errors will occur. If the type in question is one that gets promoted, the promoted type should be used as the argument to va_arg(). The following describes which types are promoted (and to what): - short is promoted to int - float is promoted to double - char is promoted to int The first use of the va_arg() macro after that of the va_start() macro returns the argument after last. Successive invocations return the values of the remaining arguments. The va_copy() macro makes dest a copy of src as if the va_start() macro had been applied to it followed by the same sequence of uses of the va_arg() macro as had previously been used to reach the present state of src. The va_copy() macro returns no value. The va_end() macro handles a normal return from the function whose variable argument list was initialized by va_start() or va_copy(). The va_end() macro returns no value. EXAMPLES
The function foo() takes a string of format characters and prints out the argument associated with each format character based on the type. void foo(char *fmt, ...) { va_list ap; int d, c; char *s; double f; va_start(ap, fmt); while (*fmt) switch (*fmt++) { case 's': /* string */ s = va_arg(ap, char *); printf("string %s ", s); break; case 'd': /* int */ d = va_arg(ap, int); printf("int %d ", d); break; case 'c': /* char */ c = va_arg(ap, int); /* promoted */ printf("char %c ", c); break; case 'f': /* float */ f = va_arg(ap, double); /* promoted */ printf("float %f ", f); } va_end(ap); } COMPATIBILITY
These macros are not compatible with the historic macros they replace. A backward compatible version can be found in the include file <varargs.h>. STANDARDS
The va_start(), va_arg(), va_copy(), and va_end() macros conform to ISO/IEC 9899:1999 (``ISO C99''). HISTORY
The va_start(), va_arg() and va_end() macros were introduced in ANSI X3.159-1989 (``ANSI C89''). The va_copy() macro was introduced in ISO/IEC 9899:1999 (``ISO C99''). BUGS
Unlike the varargs macros, the stdarg macros do not permit programmers to code a function with no fixed arguments. This problem generates work mainly when converting varargs code to stdarg code, but it also creates difficulties for variadic functions that wish to pass all of their arguments on to a function that takes a va_list argument, such as vfprintf(3). BSD
August 18, 2002 BSD
All times are GMT -4. The time now is 03:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy