Jump to content
  • Advertisement
Sign in to follow this  
SilverLogic

function(something, ...)

This topic is 5476 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Quote:
Original post by graveyard filla
but, how, in the function, do you receive / declare these parameters for use then?


I think it's some crappy macro.

By the way, don't use this with C++ (basically anything more than PODs).

Share this post


Link to post
Share on other sites
here's a little example... [smile]


#include <iostream>
#include <cstdarg>

// warning: this function is not thread safe :)
const char* format( const char* fmt, ... )
{
static char buffer[ 4096 ];
va_list arg_list;
va_start( arg_list, fmt );
vsprintf( buffer, fmt, arg_list );
va_end( arg_list );
return buffer;
}

int main()
{
const char* output;
int a = 42;
int b = 23;
int c = 65535;
float d = 29.1173f;

output = format( "1st example : %d %d\n", a, b );
std::cout << output;

output = format( "2nd example : 0x%x %.4f\n", c, d );
std::cout << output;

return 0;
}


Share this post


Link to post
Share on other sites
That example is just a dissaster waiting to happen, since you are not doing bounds checking.

I think boost library has an alternative to the variable arguments for formatting strings.

Share this post


Link to post
Share on other sites
Quote:
Original post by OrthoDiablo
That example is just a dissaster waiting to happen, since you are not doing bounds checking.

I think boost library has an alternative to the variable arguments for formatting strings.


well, indeed it is, but that's why it is an example only. i just thought it might help looking at some code actually.
i apologize if anyone had any problems with that snippet! [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!