I wanted an upper-level log API that takes in a log level (for verbosity filtering) and internally adds decorations such as a timestamp.I wanted an option to echo log strings to the console using printf.Here are some specific reasons for my logging library to pass around variadic arguments: You might think this is a strange use case: why exactly am I passing variadic arguments around? Your function counts explode: you need to provide a variadic function and a secondary implementation that accepts a va_list as input. However, my frustration arises when I need to pass the variadic arguments to another function. Access to the variadic arguments for our format stringĪt this stage, I have no specific complaints about C variadic functions. Inside the function implementation, you’ll see the C variadic constructs: // Declare a va_list which holds info needed by variadic funtions I recently implemented a logging library in C and was reminded of how much simpler variadic functions are in C++.Ĭonsider a common variadic use case: format strings with functions like printf or an equivalent log interface: void log(const char *fmt.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |