Optional Parameters in C / C++


Recently, while developing a function to help me create logs to keep track of my program for debugging purposes, I came across a need to  specify an undefined amount of parameters so that I can call functions such as CreateLog(“Function Entry: Install”, “Success”, “Remark”, “More Remark”).  Therefore, I have searched online to see whether this can be done.  To my amazement, this was in fact an easy task.  By using the __VA_ARGS__ option and vsprintf function, it can be accomplished.  I have yet the time to tidy the codes for this post but at the very least an article to help out.

If you are not sure what I meant by Optional Parameters, see here.

Article: http://www.lysator.liu.se/c/c-faq/c-7.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: