c - Matching va_list types between compilers -


i have project consists of bunch of dynamically loaded modules. originally, built msvc 2003, lately i've been working on getting work gcc. has been going pretty smoothly, except 1 problem. 64-bit code, gcc , msvc don't agree va_list is. 32-bit, things seem line fine. problem 64-bit mismatch causes when module built 1 compiler has public function va_list parameter , function called module built other compiler.

the spec says nothing va_list is, outside of section 7.15 variable arguments <stdarg.h>, paragraph 3:

the type declared is

va_list

which object type suitable holding information needed macros va_start, va_arg, va_end, , va_copy.

that paragraph means compiler dependent stuff - so, there way make these 2 compilers agree on contents of 64-bit va_list? least impact system, making gcc match msvc va_list best, i'll take solution can get.

thanks helping out!

edit:

i did 32-bit testing, , have problems there too, surprised me since there supposedly no abi differences between 32-bit intel platforms. msvc codebase i'm using defines of variadic function macros as:

typedef char *va_list; #define intsizeof(n)    ((sizeof(n) + sizeof(int) - 1) &~(sizeof(int) - 1)) #define va_start(ap, v) (ap = (va_list)&(v) + intsizeof(v)) #define va_arg(ap, t)   (*(t *) ((ap += intsizeof(t)) - intsizeof(t))) #define va_end(ap)      (ap = (va_list)0) 

i've simplified bit real project, code using test. gcc, code isn't correctly getting arguments. maybe bug, zack suggests below?

edit again:

i working results following 32-bit test application -o0, -o0, , -o2, not -o3, -os, , -oz:

typedef char *va_list; #define intsizeof(n)    ((sizeof(n) + sizeof(int) - 1) &~(sizeof(int) - 1)) #define va_start(ap, v) (ap = (va_list)&(v) + intsizeof(v)) #define va_arg(ap, t)   (*(t *) ((ap += intsizeof(t)) - intsizeof(t))) #define va_end(ap)      (ap = (va_list)0)  int printf(const char *format, ...);  int f(int n, ...) {   int r = 0;   va_list ap;    va_start(ap, n);     while (n--)     r = va_arg(ap, int);   va_end(ap);    return r; }  int main(int argc, char **argv) {   int r;    r = f(1, 1, 2, 3, 4, 5);   printf("%x\n", r);    r = f(2, 1, 2, 3, 4, 5);   printf("%x\n", r);    r = f(3, 1, 2, 3, 4, 5);   printf("%x\n", r);    r = f(4, 1, 2, 3, 4, 5);   printf("%x\n", r);    r = f(5, 1, 2, 3, 4, 5);   printf("%x\n", r);    return 0; } 

since msvc defines win64 abi, have found bug in gcc. please report in gcc bugzilla.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -