Messages in this thread | | | Date | Mon, 22 Nov 2004 12:39:54 +0100 (MET) | From | Jan Engelhardt <> | Subject | Re: var args in kernel? |
| |
>> In theory, you can't. But the way how GCC (and probably other compilers) >> implement it, you can. Because "ap" is just a pointer (which fits into a >> register, if I may add). As such, you can copy it, pass it multiple times, use >> it multiple times, and whatever you like. > >That's exactly the wrong assumption. >On some Linux architectures you can, on others you can't. >Architectures where va_list is a char or void pointer include e.g.: >i386, sparc*, ppc64, ia64 >Architectures where va_list is something different, usually struct { ... } va_list[1]; >or something similar: >x86_64, ppc32, alpha, s390, s390x
Yeah I originally had that in mind but did not write it out ;) What would the struct look like? Because if the following was true, then you could also use a pointer:
int my_printf(const char *fmt, struct { some ints, some char's, whatever } arg) { struct giveItAName *ap = &arg; callanotherfunc(fmt, ap); callanotherfunc(fmt, ap); }
>In the latter case, you obviously can't do va_list dest = src and
Mmh, I could, because GCC is wise enough to copy whole structs. This is BTW done a LOT in the kernel sources. Just compile it with -Waggreagte-return and ye'll get a whole whopping lot of warnings from GCC. For linux-2.[46].\d+.tar.bz2.
>if you do bar (x, ap); the content of the struct pointed by ap is changed >after the call, therefore you can't use it for other routines
Who said the struct is changed? The compiler could use some magic to copy above-metioned "arg" to a temporary which is only valid during my_printf() and callees. Who says the struct has to be changed? And even if it was about to, you could copy it.
>(as it depends on where exactly the called function stopped with va_arg).
Don't get me wrong, I'm just asking... in a pessimistic fashion.
Jan Engelhardt -- Gesellschaft für Wissenschaftliche Datenverarbeitung Am Fassberg, 37077 Göttingen, www.gwdg.de - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |