Handmade Hero»Forums»Code
39 posts
hitting my head against gcc
For the code added in day 328, I've been trying to understand why gcc won't create usable code, it doesn't seem to like "va_list" pointers like ArgList.

The gcc error:
1
2
3
4
src/handmade_shared.h: In function ‘umm FormatStringList(umm, char*, char*, __va_list_tag*)’:
src/handmade_shared.h:388:84: error: cannot convert ‘__va_list_tag**’ to ‘__va_list_tag (*)[1]’ 
for argument ‘2’ to ‘s64 ReadVarArgSignedInteger(u32, __va_list_tag (*)[1])’
                         s64 Value = ReadVarArgSignedInteger(IntegerLength, &ArgList);


First it changes the (va_list *) type to (__va_list_tag *), I guess with a macro or something, but "__va_list_tag" isn't a real type, (it is built into gcc), so I can't cast to it. I can cast to (va_list *) and it will compile, but it will crash with a segmentation fault when I try to open "Profile" in the debug menu.

I'm not sure how to cast to a type with a [1] in it, does it mean an array of length 1? Does it need the length information or can you replace the [1] with an * in the cast? I couldn't get a cast to work with any form of [1] in it.

By not passing "ArgList" by reference, but by value, I can get it to compile and run normally, so I can only guess that gcc is doing something strange that prevents passing a "va_list" by reference.

I've included a link to the compiling/running mod in case it's unclear.

Thanks in advance to anyone who's more familiar with this stuff.
Mārtiņš Možeiko
2562 posts / 2 projects
hitting my head against gcc
Edited by Mārtiņš Možeiko on
Yeah, this is an issue on 64-bit Intel architecture.
We already have this filed in github issues: https://github.com/HandmadeHero/cpp/issues/26
Here's an explanation why passing va_list by address is a problem: http://stackoverflow.com/a/8048892/675078

Correct way to do this is either to cast arglist to (va_list*) directly (because it is an array, and address of array is same as array) or to use va_copy to make a copy of va_list:
1
2
3
4
va_list args_copy;
va_copy(args_copy, args);
OtherFunction(..., &args_copy);
va_end(args_copy);
39 posts
hitting my head against gcc
Edited by people on
Man, that was a quick reply :)

I guess I should get around to activating a github account :P