Anyone have a reference for the representation of va_list
in the x86_64 ABI (the one used on Linux)? I'm trying to debug some code where the stack or arguments seem corrupt and it would really help to understand what I'm supposed to be seeing...
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- how to get running process information in java?
I made my comment into an answer.
This may help. It's a reference, albeit lightweight (EDIT: original link dead; replaced Wayback Machine-preserved link).
The Variable Argument List reference starts on page 50, then it goes on, page 52-53 documents
va_list
:It turns out the problem was gcc's making
va_list
an array type. My function was of the signature:and I wanted to pass a pointer to
ap
to another function, so I did:Unfortunately, array types decay to pointer types in function argument lists, so rather than passing a pointer to the original structure, I was passing a pointer to a pointer.
To work around the problem, I changed the code to:
This is the only portable solution I could come up with, that accounts for both the possibility that
va_list
is an array type and the possibility that it's not.In i386 architecture, the va_list is a pointer type. However, in AMD64 architecture, it is an array type. What is the difference? Actually, if you apply an & operation to a pointer type, you will get the address of this pointer variable. But no matter how many times you apply & operation to an array type, the value is the same, and is equal to the address of this array.
So, what should you do in AMD64? The easiest way to pass variable of va_list in a function is just passing it with no * or & operator.
For example:
It just works! And you don't need to worry about how many arguments you have got.