473,398 Members | 2,404 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,398 software developers and data experts.

Functions with variable arguments

I knew this but I have forgotten. How do you declare a function that
has to accept a variable number of arguments?

For instance, the printf() function has a variable number of arguments
it can take.

I believe languages such as Visual Basic call this feature Param
Array().

I believe the syntax had something to do with suffixing three periods
in the argument prototype, but I can't be sure. Can someone shed light
as to the syntax and also the restrictions or limitations that come
with having variable arguments in functions? Do they have to be the
last argument? It seems quite logical to think that "they" need to be
the last argument in the function definition. Are there any other
nuances to having variable arguments?

Nov 15 '05 #1
5 1687
Sathyaish wrote:

I knew this but I have forgotten. How do you declare a function
that has to accept a variable number of arguments?


You pull out your elementary C book and read it.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

Nov 15 '05 #2
"Sathyaish" <Sa*******@Yahoo.com> wrote:
# I knew this but I have forgotten. How do you declare a function that
# has to accept a variable number of arguments?
#
# For instance, the printf() function has a variable number of arguments
# it can take.

int xprintf(char *format,...) {
va_list argv;
va_start(argv,format);
.....
va_arg(argv,Type);
.....
va_end(argv);
}

--
SM Ryan http://www.rawbw.com/~wyrmwif/
I think that's kinda of personal; I don't think I should answer that.
Nov 15 '05 #3
Sathyaish wrote:
I knew this but I have forgotten. How do you declare a function that
has to accept a variable number of arguments?

[snip]

You use the ellipses (...) to decl. a function that accepts variable
number of arguments.

It could be:

void myVarArgs(char *fmt, ...);

and then in the defintion you could va_args, va_start library calls.

Nov 15 '05 #4


Jaspreet wrote:
Sathyaish wrote:
I knew this but I have forgotten. How do you declare a function that
has to accept a variable number of arguments?
[snip] and then in the defintion you could va_args, va_start library calls.

1. No such thing as va_args.
2. va_arg, va_end, and va_start are macros, not library calls
Regards,
Suman.

Nov 15 '05 #5
Suman wrote:
Jaspreet wrote:
Sathyaish wrote:
I knew this but I have forgotten. How do you declare a function that
has to accept a variable number of arguments?

[snip]
and then in the defintion you could va_args, va_start library calls.

1. No such thing as va_args.
2. va_arg, va_end, and va_start are macros, not library calls
Regards,
Suman.


Thanks for correcting me. Apologies for the typos.

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
9
by: Gibby Koldenhof | last post by:
Hiya, Terrible subject but I haven't got a better term at the moment. I've been building up my own library of functionality (all nice conforming ISO C) for over 6 years and decided to adopt a...
1
by: S?ren Gammelmark | last post by:
Hi I have been searching the web and comp.lang.c of a method of using variable-argument function pointers and the like. And some of the questions arising in this post are answered partly in...
16
by: Martin Jørgensen | last post by:
Hi, Problem: ======== Some of my output functions are beginning to take pretty many arguments... I mean.... We're talking about 10-15 arguments :-) So I thought to myself, perhaps this is...
6
by: Fuzzyman | last post by:
Hello all, I'm trying to extract the code object from a function, and exec it without explicitly passing parameters. The code object 'knows' it expects to receive paramaters. It's 'arg_count'...
6
by: CptDondo | last post by:
How do you declare a function with 0 or mroe arguments? I have a bunch of functions like this: void tc_cm(int row, int col); void tc_do(void); void tc_DO(int ln); and I am trying to ...
2
by: Alan | last post by:
I have a couple of questions about using a variable number of arguments in a function call (...). The context is that I have some mathematical functions I created. I currently pass them a pair of...
9
by: oldyork90 | last post by:
I'm going thru code and have never seen this before http://www.webreference.com/programming/javascript/mk/column2/3.html Look at function CreateDragContainer() on line 25. It has no arguments...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.