Bizarre C++ syntax
I found this piece of code in the dx8sdk cd in a little program called "cutscene"(I was trying to find an easy way to add some cutscene video in the game I am implementing). What can you make out of this function declaration?
void Msg(TCHAR *szFormat, ...)
{
// Large buffer for very long filenames (like with HTTP)
TCHAR szBuffer[512];
...blah blah...
// This sample uses a simple message box to convey warning
// and error messages. You may want to display a debug string
// or suppress messages altogether, depending on your
// application.
MessageBox(NULL, szBuffer, "PlayCutscene Error", MB_OK);
}
declared earlier as:
static void Msg(TCHAR *szFormat, ...);
and used in the program in several cases like:
if(FAILED(hr))
{
Msg(TEXT("Failed(%08lx) to set fullscreen!\r\n"), hr);
return hr;
}
It compiled fine in visual studio 6.0, but... what the hell these dots are for?!?
January 18, 2002 03:06 PM
Those dots are for a variable number of arguments. The function is expected to have some method of determining how many arguments were passed. For example, string format functions are passed the "%s %d" format string which indicates there were two variable arguments passed to the function.
-enjoy
mike kurth
-enjoy
mike kurth
this is a va list...
learn more about them here.
-eldee
;another space monkey;
[ Forced Evolution Studios ]
learn more about them here.
-eldee
;another space monkey;
[ Forced Evolution Studios ]
-eldee;another space monkey;[ Forced Evolution Studios ]
Thanks Mike and eldee. After a bit of search I found it: the predefined types for managing variable arguments (va_list, va_start and va_end). I wonder, however, where these come handy. Is there no end to the weird stuff in C?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement