473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Passing multiple arguments

cypherzero
Some C functions like printf take an unlimited number of arguments of various types.
Does anyone know how such a function is created, stdio.h doesn't give much of a clue, specifying only '...' and not how the values are actually obtained by the function itself.

Thanks in advance.
Sep 3 '07 #1
1 10866
weaknessforcats
9,208 Expert Mod 8TB
Check out the va_arg macros and the ellipsis operator.

The printf() function prototype looks like:

Expand|Select|Wrap|Line Numbers
  1. int printf(const char* arg, ...);
  2.  
The arg string is parsed using macros:

va_list
va_start
va_arg
va_end

The ellipsis (...) is a placeholder for a variable number of arguments.

In the case of printf(), the number of % signs is counted and that tells how many arguments the ellipsis contains.

Just read up on how to use these macros.

It's in the K&R ANSI C Programming Language Prentice Hall 1988.
Sep 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
2
by: xideum | last post by:
Hi. Question: In a function that takes multiple arguments, each with a default value setis there anyway to either alter the order of the parameters you pass to it or skip the passing of certain...
2
by: pyrexia | last post by:
Greets all. I'm attempting to write an app that will be used as a 'control/launcher' application for other apps. For the sake of argument let's say the app is launched from a command line: ...
3
by: KK | last post by:
Hello all, I have several classes binded by one common interface - say 'sum' interface which calculates the sum of all the class elements of type 'int'. class Alphabet { int _a; int _b; int...
7
by: John Layton | last post by:
Hi there, Is it possible to pass null to a function taking an "out" (or "ref") parameter in C#. I'd like to do something like the following (which doesn't compile of course). Thanks in advance....
4
by: Nathan Sokalski | last post by:
I am a beginner with AJAX, and have managed to learn how to use it when passing single parameters, but I want to return more than one value to the client-side JavaScript function that displays it....
5
by: goldtech | last post by:
Hi, I'm passing what I think is a string parameter to another Python program (spawn.py) - see the code snip below. But only the counter part gets printed to a log file via spawn.py. Yet the...
1
by: Ben Warren | last post by:
Hello, Let's say I have a function with a variable number of arguments(please ignore syntax errors): def myfunc(a,b,c,d,...): and I have a tuple whose contents I want to pass to the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.