Archived

This topic is now archived and is closed to further replies.

varargs compiler construct.

This topic is 5624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites