* function call argument count @ 2004-05-23 22:01 don fisher 2004-05-24 12:31 ` Eljay Love-Jensen 2004-05-24 20:57 ` Justinas 0 siblings, 2 replies; 4+ messages in thread From: don fisher @ 2004-05-23 22:01 UTC (permalink / raw) To: gcc-help Hello, Is there a call that can be made from within a function to determine how many arguments have been passed to it? I feel such a call would be of great assistance when used in conjunction with variable length argument lists. In the "old days", VMS pushed a parameter count as part of the call frame. You could even determine which variables were null, since they always did call by reference and null parameters were indicated by a zero address. Sorry if this is well known, or an invalid request for some reason. thanks don -- ------------------------------------------------------------------- | Don Fisher dfisher@as.arizona.edu | | Steward Observatory | | 933 N. Cherry Ave. VOICE: (520)621-7647 | | University of Arizona FAX: (520)621-9843 | | Tucson, AZ 85721 | ------------------------------------------------------------------- ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: function call argument count 2004-05-23 22:01 function call argument count don fisher @ 2004-05-24 12:31 ` Eljay Love-Jensen 2004-05-24 13:47 ` Chris Wolstenholme 2004-05-24 20:57 ` Justinas 1 sibling, 1 reply; 4+ messages in thread From: Eljay Love-Jensen @ 2004-05-24 12:31 UTC (permalink / raw) To: don fisher, gcc-help Hi Don, There's not an easy way that is platform agnostic to determine the argument count. You can do it yourself as a convention: void MyFunc(int argcount, ...); Then call it with the explicit argument count, via: int a=1, b=2, c=3; MyFunc(3, a, b, c); I recommend that variable arguments be passed in as a std::vector<> or std::map<> or std::set<> or whatever kind of container is appropriate. Or better yet, as generic begin() and end() iterators to the aforementioned containers. By "generic" I mean using templates. HTH, --Eljay ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: function call argument count 2004-05-24 12:31 ` Eljay Love-Jensen @ 2004-05-24 13:47 ` Chris Wolstenholme 0 siblings, 0 replies; 4+ messages in thread From: Chris Wolstenholme @ 2004-05-24 13:47 UTC (permalink / raw) To: don fisher, gcc-help Of course using a vector, map, etc. only works if all the parameters are of the same type. Using the explicit count is a better option for different argument types (if the type order is known). I sometimes use some defined value before each variable to say there is another parameter and to give a clue to the type, and then use a different value to define the end of the list. These can be #defines or an enumerated type. For example: enum Var_Types { End = 0, Int, Double, String }; void myFunc(Var_Types more,...); Then: myFunc(End); would mean no parameters and myFunc(Int, 1, Int, 3, Double, 5.8, String, "Hello", String, "Goodbye", End); You then test the Var_Types value, and the next parameter according to it. You could use something similar for a parameter list with all the same type if you have a value you know won't be passed in and can use it as a terminator - e.g. expecting positive integers could end with a value of -1. This was just in case you're interested in lists with different types... :-) Chris ----- Original Message ----- From: "Eljay Love-Jensen" <eljay@adobe.com> To: "don fisher" <dfisher@as.arizona.edu>; <gcc-help@gcc.gnu.org> Sent: Monday, May 24, 2004 1:30 PM Subject: Re: function call argument count > Hi Don, > > There's not an easy way that is platform agnostic to determine the argument > count. You can do it yourself as a convention: > > void MyFunc(int argcount, ...); > > Then call it with the explicit argument count, via: > > int a=1, b=2, c=3; > MyFunc(3, a, b, c); > > I recommend that variable arguments be passed in as a std::vector<> or > std::map<> or std::set<> or whatever kind of container is appropriate. Or > better yet, as generic begin() and end() iterators to the aforementioned > containers. By "generic" I mean using templates. > > HTH, > --Eljay > > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: function call argument count 2004-05-23 22:01 function call argument count don fisher 2004-05-24 12:31 ` Eljay Love-Jensen @ 2004-05-24 20:57 ` Justinas 1 sibling, 0 replies; 4+ messages in thread From: Justinas @ 2004-05-24 20:57 UTC (permalink / raw) To: gcc-help On Sun, 23 May 2004 15:01:04 -0700 don fisher <dfisher@as.arizona.edu> wrote: > Hello, > > Is there a call that can be made from within a function to determine > how many arguments have been passed to it? I feel such a call would be > of great assistance when used in conjunction with variable length > argument lists. In the "old days", VMS pushed a parameter count as > part of the call frame. You could even determine which variables were > null, since they always did call by reference and null parameters were > indicated by a zero address. > > Sorry if this is well known, or an invalid request for some reason. > thanks > don > -- > ------------------------------------------------------------------- > | Don Fisher dfisher@as.arizona.edu | > | Steward Observatory | > | 933 N. Cherry Ave. VOICE: (520)621-7647 | > | University of Arizona FAX: (520)621-9843 | > | Tucson, AZ 85721 | > ------------------------------------------------------------------- > hi, one idea: try to compare esp, a stack pointer(x86, i'm not sure how ir would be on other platforms). Sure, this works when you know the size of variable, and they should be same type... Justinas. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-05-24 20:57 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2004-05-23 22:01 function call argument count don fisher 2004-05-24 12:31 ` Eljay Love-Jensen 2004-05-24 13:47 ` Chris Wolstenholme 2004-05-24 20:57 ` Justinas
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).