• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

parameters


Hi,

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

bye
cbasavaraj
0
cbasavaraj
Asked:
cbasavaraj
  • 2
  • 2
  • 2
  • +3
1 Solution
 
captainkirkCommented:
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
 
nietodCommented:
>> 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
 
captainkirkCommented:
that would be more precisely correct...
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
ozoCommented:
There may be an implementation defined limit, but a conforming implementation shall be able to translate a program containing at least 31 parameters.
0
 
jasonclarkeCommented:
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
 
nietodCommented:
What section is that from?  I don't remember that.
0
 
jasonclarkeCommented:
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
 
abancroftCommented:
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
 
ozoCommented:
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
 
RONSLOWCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now