This is the mail archive of the
mailing list for the GCC project.
Knowing the number of variable arguments.
- To: gcc-help at gcc dot gnu dot org
- Subject: Knowing the number of variable arguments.
- From: Gigi Sullivan <sullivan at sikurezza dot org>
- Date: Mon, 29 May 2000 19:05:26 +0200
I'm not sure this is the right mailing list and I search
a little bit the archive, but didn't find the right answer ...
so please forgive me :)
Let consider this simple function prototype:
func(char, int, ...);
Well, I know that using va_start/va_arg and va_end I can
scan all the variable arguments list, but what if I'd like
to know the *number* of the variable arguments?
I'm saying so, since the argument type (in my .c file) isn't
int, but it's a union (or it could be a struct too - but right now
a union) and as man said, when there are no other argument in
the list, va_arg returns random errors.
This is bad, since I cannot know *when* the list is terminated
(and I cannot do like the example showed to me, i.e. using pointer +
while and switch etc etc).
I tried to search about some __buitin_*, but I didn't find anything
to suite my needs.
Well, I indeed solved the problem, but it's strictly non-portable
since I played with the saved frame pointer (to know the caller frame
address) and with the address of the first argument in `func' (even
if no asm code were used, tho. Still not-portable, I guess due to
different calling convention. The CPU is an Intel x86).
So I was wondering if someone could point me out a solution
like some magic macro, such as GIMME_ARGS_NUMBER :)
Thx for all.
-- gg sullivan
I apologize for my bad english.
Lorenzo Cavallaro `Gigi Sullivan' <email@example.com>
Until I loved, life had no beauty;
I did not know I lived until I had loved. (Theodor Korner)