473,396 Members | 1,774 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 parameter to a function

shoonya
161 100+
what does this declaration mean ??

Expand|Select|Wrap|Line Numbers
  1. void Foo( int a, int b, ... ){
  2. ..
  3. }
Shoonya
Sep 30 '08 #1
5 1510
r035198x
13,262 8TB
Google "variable number of arguments in c".
Sep 30 '08 #2
A function with no return value, and integer variables passed as parameters to the function called a and b in the function.
Sep 30 '08 #3
donbock
2,426 Expert 2GB
Are you familiar with the printf() function? Its first argument is a format string that encodes the number and meaning of the following arguments. Notice that you can pass a different number of arguments each time you call printf() without provoking any compiler warnings about violating the function prototype.

The function prototype for printf follows:
int printf(const char *fmt, ...);

The normal job of a function prototype is to inform the compiler of the function's calling protocol so that compile-time checks can be performed to verify that the function was called properly.

The "..." construct in a prototype informs the compiler not to concern itself with which arguments appear beyond this point. It is up to the programmer to get it right. You're performing without a net!

This variable argument list feature provides great flexibility; but at the cost of reduced compile-time checking and increased complexity if you try to write a such a function.
Sep 30 '08 #4
shoonya
161 100+
hi donbock,

Thanks a lot

Shoonya
Oct 2 '08 #5
Actually, this methodology is not difficult to use, and is extrenely powerful. An example is the best way to show how it works. The following routine is used as a graceful exit from a program when things don't go right. It is used like printf in that you can send a variable amount of data to the function

1st the code:
make sure that you include <stdarg.h>

Expand|Select|Wrap|Line Numbers
  1. #include <stdarg.h>
  2.  
  3. void SysAbort(char *String, int NumArgs, ...)
  4. {
  5.    va_list       ap;
  6.    va_start(ap, NumArgs);
  7.  
  8.    vfprintf(stderr, String, ap);
  9.  
  10.    va_end(ap);
  11.  
  12.    // Check if n\memory needs to be cleaned up
  13.    MyCleanupRoutine();
  14.    exit(1);
  15. }
This can be called as follows

Expand|Select|Wrap|Line Numbers
  1. SysAbort("Unable to open file %s from path %s", 2, FileName, Path);
The '2' in the call tells the SysAbort function that there are two arguments following, the results would (assuming FileName = "InFile.txt" and Path = ""C:\Data\NewData" look like:

'Unable to open InFile.txt from path C:\Data\NewData'

The same as printf.
Oct 3 '08 #6

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

Similar topics

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...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
2
by: diffuser78 | last post by:
I wrote a small app in wxPython using wxGlade as designer tool. wxGlade brings and writes a lot of code by itself and thats where my confusion started. Its about parameter passing. Here is my...
2
by: Nab | last post by:
I have just tried to pass parameters to a procedure in VB 2005 and realised that you only need to pass the input parameter. The output parameter's value will be returned without the need to pass it...
10
by: amazon | last post by:
Our vender provided us a web service: 1xyztest.xsd file... ------------------------------------ postEvent PostEventRequest ------------------------------------- authetication authentication...
0
by: amazon | last post by:
I have web service that acceping following parameters.. postev.PostEvent(authentication as ws.authentication, name as string,id as string, exdate as date, parameter() as ws.nameparametervaluepair...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
12
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
10
by: Janus | last post by:
Hi, Is there a way to pass arguments to the callback function used inside an addEventListener? I see that I can only list the name of the callback function. For eg, I use this: var...
4
by: Deckarep | last post by:
Hello fellow C# programmers, This question is more about general practice and convention so here goes: I got into a discussion with a co-worker who insisted that as a general practice all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
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...

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.