Skip to main content
gamedev.net
🔒 Locked

varargs compiler construct.

Started by jwalker Jul 25, 2002 at 10:07 PM 1 replies 200+ views
Original Post
jwalker
jwalker
does anyone know how to compiler for C can resolve the ... arguments? the assembly for it is so confusing?, how does it set up the ... construct ???? Its my duty, to please that booty ! - John Shaft
Zipster
Zipster
I don''t think it does resolve them. It''s up to the implementation to handle them properly. There isn''t even any type checking! Of course I could be wrong, I''m just speaking from speculation
niyaw
niyaw
tried looking at the va_* macros? basically, you just have a pointer to the stack and you''re advancing it by the size of the elements you are retrieving.

let''s say you have the following function:

void f(int x, ...);

and you''re calling it as

f(x, (int) y, (double) z);

the stack would look like this:


----
z (8 bytes)
----
y (4 bytes)
----
x (4 bytes)
----

va_start positions the argument pointer at y, no different than using any pointer.

va_arg returns the data where the pointer points to. you specify which type you want, and the macro performs casting. then it uses some knowledge about how stack is organized to advance the pointer to the next element. if you use

int y = va_arg(list, int);

the macro will advance the pointer ''list'' up by sizeof(int) bytes, thus pointing it at z. you get the contents of y.

umm... hope this was of some use.

and for the your specific question, the compiler does absolutely nothing to deal with ... arguments, it just ignores them. if you want to get to those arguments, you need to write the code, which is what va_* macros provide.

---
Come to #directxdev IRC channel on AfterNET

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.