Original Post
🔒 Locked
varargs compiler construct.
Advertisement
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:
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
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.
Advertisement