Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-25-2004, 12:49 AM   #1
Senior Member
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 49
How does printf work?

Hi, me again..

I have a class (the language is C++) that has a function used for putting text into a logfile.
Loghandler::log(const char *text);

This works out but now I need a more powerful way to do this. I need to be able to send variables as arguments, like you do to printf().
Loghandler::log(const char *format, ...);

I tried and using ... as type worked, the compiling worked. But how can I manage this? Can I do a function that works like printf and then use it to log the whole, processed string?
Old 12-25-2004, 03:06 AM   #2
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
       stdarg - variable argument lists

       #include <stdarg.h>

       void va_start( va_list ap, last);
       type va_arg( va_list ap, type);
       void va_end( va_list ap);

       A  function  may  be called with a varying number of argu-
       ments  of  varying  types.   The  include  file   stdarg.h
       declares a type va_list and defines three macros for step-
       ping through a list of arguments whose  number  and  types
       are not known to the called function.
You can find much more information from man stdarg

You're doing right by using ... in the parameter list. the va_*() functions just let you pull those arguments off the stack.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
printf problem??? Programming 2 11-13-2005 08:45 PM
is a printf wrapper possible? Thinking Programming 2 10-21-2005 07:44 AM
c printf question. fredgt Programming 5 09-09-2004 05:06 AM
More arguments in printf() AMMullan Programming 3 02-23-2004 02:29 PM
printf new_user10 Programming 3 09-09-2003 11:12 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:35 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration