|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] More Variable-Length Functions
After reading the discussion on variable-length functions, I decided to go make myself one that would be like prinf(), only printing onto the game screen somewhere using extra game-ish features. So, first I used the va_start() macro with a va_list variable and the last normal argument passed to the function. After that, I stepped through the first argument (a format string) looking for '%' escape characters. Upon finding one, I add it's length to the original length of the format string. That's how I find out how long the final string is. Now how do I go back and use my arguments again? I'm using the va_end() macro, then calling va_start() again to get back to the beginning. It's worked so far, but I really have no idea if it's safe, portable, standard, or correct to do this. Now I allocate the size of the string, plus one, and go through the whole format string again, this time writing the characters into the newly allocated memory. Is this really a good way to do this, or should I try something else? Does anyone know how printf() et similar functions work? -[ Neil-Edelman -- dreaded.neil@phreaker.net -- ICQ UIN: 705130 -[ http://neil.freeshell.org/ -- http://moop.bizland.com/ -[ "My air-to-air missile overrides your air traffic control clearance" ================================================================= The GameProgrammer.Com mailing list is for the open discussion of any topic related to the art, science, and business of programming games. This list is especially tolerant of beginners. We were all beginners once To SUBSCRIBE or UNSUBSCRIBE please visit: http://gameprogrammer.com/mailinglist.html
|
|