I have the following function:
void Register(Data* _pData, uint32 _Line, const char* _pFile, ...)
{
va_list Args;
va_start(Args, _pFile);
for(uint i = 0;i m_NumFloats; ++i)
{
_pData->m_Floats[i] = va_arg(Args, fp32);
}
va_end(Args);
}
Which is called by the macro:
#define REG(_Name, ...)\
{\
if(s_##_Name##_Data.m_Enabled)
Register(&s_##_Name##_Data, __LINE__, __FILE__, ##__VA_ARGS__);\
}\
With the usage:
REG(Test, (fp32)0.42f);
The Data-struct looks like:
struct Data
{
int m_NumFloats;
fp32 m_Floats[4];
}
The creation-macro of Data creates the static Data g_YourName_Data and initializes it correctly with a maximum of 4 m_NumFloats.
The va_arg call resolves to 0.0. s_Test_Data exists and the Register-function is called appropriate. va-list just simply won’t let me resolve the first argument into the float that I passed it into. Is there anything specific that I’m missing?
Try:
Get rid of the token-pasting operator. You we’re also missing a ‘\’ in your macro (maybe a copy-n-paste error?).
Also, use
va_arg(), notva_args(). And I’m not sure if you meant for_Nameto be_Name_Dataor the other way around.Finally, I assumed that
fp32was an alias forfloat; GCC had this to say to me:You should heed that warning. The program does crash for me if I do not.