?
Solved

parameters

Posted on 2000-04-10
10
Medium Priority
?
250 Views
Last Modified: 2010-04-02

Hi,

What is the maximum nor of parameters can we pass in a function?

bye
cbasavaraj
0
Comment
Question by:cbasavaraj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
10 Comments
 
LVL 4

Expert Comment

by:captainkirk
ID: 2701365
I don't believe there is a maximum defined, but since function parameters are passed on the stack, I would assume (correct me if I'm wrong) that the maximum stack size would determine where you hit the wall on this one...
0
 
LVL 22

Expert Comment

by:nietod
ID: 2701491
>> I don't believe there is a maximum defined,
right, there is no maximum

>> I would assume (correct me if I'm wrong) that
>> the maximum stack size
The maximum stack size is the upper theoretical limit.  The actual limit will be less than that because there will be other things on the stack as well.

0
 
LVL 4

Expert Comment

by:captainkirk
ID: 2701504
that would be more precisely correct...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 84

Expert Comment

by:ozo
ID: 2701674
There may be an implementation defined limit, but a conforming implementation shall be able to translate a program containing at least 31 parameters.
0
 
LVL 9

Expert Comment

by:jasonclarke
ID: 2701807
the standard actually says:

The limits may constrain quantities that include those described below
  or others.  The bracketed number following  each  quantity  is  recom-
  mended  as  the  minimum for that quantity.  However, these quantities
  are only guidelines and do not determine compliance.

--Parameters in one function definition [256].

....so if there is no actual figure specified by the standard, but 256 must be assumed to be a reasonable minimum...


0
 
LVL 22

Expert Comment

by:nietod
ID: 2702000
What section is that from?  I don't remember that.
0
 
LVL 9

Expert Comment

by:jasonclarke
ID: 2703172
its in the limits section - in the draft at least - which I think is almost the last appendix.

As it says though, these things are only guidelines and useful minimums, they do not make or break standards conformance.
0
 
LVL 4

Expert Comment

by:abancroft
ID: 2703914
Looks like there is no maximum other than the stack size, but if you do run into some limit (e.g. one imposed by your compiler), you can always define a struct that stores the parameters, then allocate an instance of the struct on the heap (using new) & pass a pointer to it.

Don't forget to delete the struct after the call.

Or even better, use auto_ptr.
0
 
LVL 84

Expert Comment

by:ozo
ID: 2705229
and I was looking at the C standard, not the C++ standard.

of course, there may be an implementation imposed limit on the number of members in a single struct too...
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 40 total points
ID: 2706049
It is implementation dependant.

It depends on the size of the args being passed etc.

Genreally, if there is a LOT of individual items to be passed, you are better putting them into a struct and passing that instead (preferably by (const) reference)

That way, you have a lot of data, but only one parameter.

Lots of parameters is a BAD idea.  At least with a struct there is some naming (ie each item in the struct has a name) parameters are purely positional.

A neat 'trick' is to use member functions and operator() to do something a bit like named parameters (where order doesn't matter).

struct Function {
  void operator() {
   ... do the work here ..
  }
  F& Name(char* name) { m_name = name; return *this; }
  F& Age(int age) { m_age = age; }
  ... etc
};

call it like this

Function().Name("Roger")..etc...Age(39)();

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question