Va_args and 64 bits

I’m a leading developer of Bitfighter and I have problems porting the game to 64-bit Linux. This should be a relatively simple and common problem, but it has surpassed many people, and I could not find any good information about it.

[[The code compiles in the 32-bit version with gcc version 4.1.2 and others and does not work with several versions of 64-bit Linux, but I rely on reports from others and do not have the exact version of gcc that fails. But it fails for a few people, on different tastes of Linux. I am 99% sure that this is not a problem with the compiler version. ]]

I have the following:

 void UserInterface::drawCenteredString(int y, int size, const char *format, ...)
   {
    va_list args; 
    va_start(args, format); 
    char buffer[2048]; 
    dVsprintf(buffer, sizeof(buffer), format, args); 
    va_end(args);

    drawCenteredString2(y, size, buffer);
 }   

 // Elsewhere, in platform.cpp... (this is where the error occurs)

 S32 dVsprintf(char *buffer, int bufferSize, const char *format, void *arglist)
 {
    return vsnprintf(buffer, bufferSize, format, (char *) arglist);
 }

This works great on 32-bit platforms. However, when I compile it on 64-bit Linux, it fails:

 platform.cpp:457: error: cannot convert 'char*' to '__va_list_tag*' for argument '4' to 'int TNL::vsnprintf(char*, size_t, const char*, __va_list_tag*)'

, :

return vsnprintf(buffer, bufferSize, format, (va_list) arglist);

.

- , , 64- ?

, :-) - , va_list_tag?

!

============================================ >

, , :

logprintf("Hello %s", name);

void logprintf(const char *format, ...)
{
   va_list s;    
   va_start( s, format );

   logger(LogConsumer::GeneralFilter, format, s);
   va_end(s);
}

void logger(LogConsumer::FilterType filtertype, const char *format, va_list args)
{
   char buffer[4096];

   vsnprintf(buffer, sizeof(buffer), format, args);

   Platform::outputDebugString(buffer);
}
+3
4

S32 dVsprintf(char *buffer, int bufferSize, const char *format, void *arglist)

S32 dVsprintf(char *buffer, size_t bufferSize, const char *format, va_list arglist)

.

+5

-, dVsprintf .

S32 dVsprintf(char *buffer, int bufferSize, const char *format, void *arglist)

arglist va_list .

-, vsnprintf dVsprintf?

-, drawCenteredString , :

void UserInterface::drawCenteredString(int y, int size, const char *format, ...)
{
    ///...
    drawCenteredString(y, size, buffer);
}   

__va_list_tag* va_list. , va_list gcc , .

+3

:

S32 dVsprintf(char *buffer, int bufferSize, const char *format, ...)
{
    va_list va_args;
    va_start( va_args, format );
    S32 result = vsnprintf(buffer, bufferSize, format, va_args); 
    va_end( va_args );
    return result;
}

__va_list_tag* - ..., char* typecast - 32 ...

, ++, ++-, va_args? :

+2

stdarg.h out... osprey/obj/include, to fix_starg.h, soved , , , , stdarg.h, , : #include, - stdarg.h, ... kernel/obj/include . ( types.h ). kernel/include in bionic, kernel/obj/incudes kernel/obj/includes/linux, , . , -, , . , , .

0
source

Source: https://habr.com/ru/post/1730027/


All Articles