This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
va_ref
- From: Ryan Lortie <desrt at desrt dot ca>
- To: GCC List <gcc at gcc dot gnu dot org>
- Date: Sat, 25 Aug 2007 11:51:34 -0400
- Subject: va_ref
Hello GCC List.
I am not on this list, so please keep me cc:'d on any replies.
I recently found something about C that I do not like at all. I was
enraged and furious! I blogged!
http://blogs.gnome.org/desrt/2007/08/22/isoiec-98991999-e-%c2%a7-67537/
I am proposing the following feature for GCC to mitigate the problem: a
new macro (defined in <stdarg.h> under -std=gnu99 or an appropriate
#define) called va_ref().
va_ref() would be defined in such a way as to allow the following
program to be correct and to output
--snip--
1 = 1
2 = 2
--snip--
#include <stdarg.h>
#include <stdio.h>
static void
print (int x, va_list *app)
{
printf ("%d = %d\n", x, va_arg (*app, int));
}
static void
do_both (va_list ap)
{
print (1, va_ref (ap));
print (2, va_ref (ap));
}
static void
varfunc (int ignore, ...)
{
va_list ap;
va_start (ap, ignore);
do_both (ap);
va_end (ap);
}
int
main (void)
{
varfunc (0, 1, 2);
return 0;
}
Essentially, on machines where va_list has a structure or scalar type,
you would have something to the effect of
#define va_ref(x) (&(x))
and on machines with va_list as an array you would have something like
#define va_ref(x) ((va_list *)(x))
That is all.
Cheers