This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Knowing the number of variable arguments.


Alexandre Oliva wrote:

> On May 29, 2000, Gigi Sullivan <sullivan@sikurezza.org> wrote:
>
> Nope.  If you pass a list of pointers, the last of which is NULL, then
> you can certainly expect va_arg to work correctly on all platforms, as
> long as you tell it each argument is the appropriate pointer type.
>
> >       Not all pass parameters on the stack (that could grows towards
> >       lower/upper address).
>
> va_arg will take care of this for you.
>
> > Could be this an addendum to the current gcc?
>
> What kind of extension are you thinking of?
>

This was initially stated to be for a C program, or .c anyway, and I'm
wondering what stage of development this program is at.  If early and there
wouldn't be much to convert, then couldn't this be done in C++, using
inherent language support?

I haven't worked in or looked at C++ for some time, but remember something
about methods inherently being able to accept a variable number of
arguments, albeit maybe one is always needed.   I have books and could
verify this, but am lazy and will just throw out the idea.  There's
probably someone out there with more experience using this particular C++
capability, because I've never need to use it.

From what I recall, this was only covered for methods.  I don't recall
anything being specifically said about variable command line argument
lists.

Isn't there a getopt or getopts C function?  There is for shell script and
it (I believe) requires -{option}'s, i.e., option switches, to be used (not
sure if the switches are necessary), but seem to remember reading
somewhere, maybe in Perl, that the script getopt function was associated
with the C function, and this would be GNU C.  Perl has been ported to
other OSs and I believe it's getopt function is supported on all;
therefore, GNU C getopt or what ever the correct name is would probably
also be equally supported or portable.

Check for the getopt function (name may be a little different) to see if
this is portable and exists.

With getopt, at least with the option switches, you need to account for all
possibilities and defaults, although default could be the only thing the
block does or does not do, and you code according to what ever the logic is
for the command line.  Perhaps I don't understand the problem in question
well enough, but this is simple to do in script.

If this is a new program and little has been written, then maybe Perl would
be a solution, if you can't determine how to do this in C or C++.

mike




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]