For example, I have
I want to pass in 2 types: INFO("str") and INFO("str, %d", int). For the 2 types, shall I tell if ap is empty?Code:void INFO(const char* fmt, ...){ char buf[1024] va_list ap; vsnprintf(buf, 1024, fmt, ap); va_end(ap); return; }
This is a discussion on How to tell a va_list object is empty? within the C++ Programming forums, part of the General Programming Boards category; For example, I have Code: void INFO(const char* fmt, ...){ char buf[1024] va_list ap; vsnprintf(buf, 1024, fmt, ap); va_end(ap); return; ...
For example, I have
I want to pass in 2 types: INFO("str") and INFO("str, %d", int). For the 2 types, shall I tell if ap is empty?Code:void INFO(const char* fmt, ...){ char buf[1024] va_list ap; vsnprintf(buf, 1024, fmt, ap); va_end(ap); return; }
There is no way to tell by looking at the va_list. When you see the "%d" you assume there is an argument.
Yes, because you don't initialize the va_list with va_start. Other than that, no.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Well, that, and other than that missing semicolon.Other than that, no.
That return is unnecessary as well. And consider using sizeof() rather than hard-coding 1024 into that vsnprintf() call.Code:void INFO(const char* fmt, ...){ char buf[1024]; va_list ap; va_start(ap, fmt); vsnprintf(buf, 1024, fmt, ap); va_end(ap); return; }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.