Recently I came to this function (used in a logger class) I think what is this , but I do not know how :
zero reporter :: print (const char * szFormat, ...) {// note: M_out Is a FILE * va_list args; Va_start (RGS, SJ format); Vfprintf (M_out, SJ format, Args); Va_end (args); } I have read, but still it is unclear to me. Do I have the most anger that it does not work as expected, I get 0 for the last number and string (Blank), although it should print some more than 0 file paths
Case 1:
rep.print ("Value:% 08X% 08X% 08X% 08X% 08X% 08X% d% s \ N ", val1, val2, val3, val4, val5, val6, source.getLength (), sspath); // source.GetLength () returns an size_t, SAPPAR is a constant char * and this is actually a valid string but it is OK to change it to:
< P> Case 2: rep.print ("value:% 08X% 08X% 08X% 08X% 08X% 08X", val1, val2, val3, val4 , Val5, val6); Rep.print ("% d% s \ n", source.GetLength (), szPath); Note that I am compiling under MSVC ++ 2008. The same code works fine under GCC (the first case too). Do I use the function in the implementation of the reporter :: print () or in the bug? How can I make sure that even if called in the first case, will it work fine? And why is this also unsuccessful?
reporter :: print is fine. All those who are doing this are starting the args to refer to the variable logic list, then send that variable logic list to vfprintf () Who knows what to do with it.
Your problem is that the % d format specifier (which requires the int type logic) that source.GetLength () < / Code> (which I can guess is probably a size_t ) If you know that the length always fits into a int , you can solve it with a cast conversion:
..., (int ) Source.GetLength (), ... (This is because the expected types of arguments that are part of the variable logic list, do not go for the compiler in contrast to a typical prototype function declaration goes).
Comments
Post a Comment