Advertisement

Bizarre C++ syntax

Started by January 18, 2002 03:03 PM
4 comments, last by ghost1206 22 years, 9 months ago
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?!?
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
Advertisement
this is a va list...
learn more about them here.

-eldee
;another space monkey;
[ Forced Evolution Studios ]

Vash says: eat more donuts, play more games!

-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?
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?
quote: Original post by ghost1206
I wonder, however, where these come handy.

See printf().
quote: Is there no end to the weird stuff in C?

Um, no.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

This topic is closed to new replies.

Advertisement