In C, is it possible to forward the invocation of a variadic function? As in,
int my_printf(char *fmt, ...) {
fprintf(stderr, "Calling printf with fmt %s", fmt);
return SOMEHOW_INVOKE_LIBC_PRINTF;
}
Forwarding the invocation in the manner above obviously isn't strictly necessary in this case (since you could log invocations in oth...
I want to write a macro in C that accepts any number of parameters, not a specific number
e.g.
#define macro( X ) something_complicated( whatever( X ) )
where X is any number of parameters
I need this because whatever is overloaded and can be called with 2 or 4 parameters.
I tried defining the macro twice, but the second definiti...
I have a daemon that reads a configuration file in order to know where to write something. In the configuration file, a line like this exists:
output = /tmp/foo/%d/%s/output
Or, it may look like this:
output = /tmp/foo/%s/output/%d
... or simply like this:
output = /tmp/foo/%s/output
... or finally:
output = /tmp/output
I hav...
I am curious and hopefully someone can shed somelight on this - but why do the C# functions that take 'params' have to be an array?
I get that the objects in the parameters list are entered into an array but what if someone wants to create a variadic function that takes in an undefined number of array objects?
Take this function for ex...
Hi there.
I was wondering if there was any way to pass parameters dynamically to variadic functions. i.e. If I have a function
int some_function (int a, int b, ...){/*blah*/}
and I am accepting a bunch of values from the user, I want some way of passing those values into the function:
some_function (a,b, val1,val2,...,valn)
I don...
Hi,
I was wondering if it is possible to iterate over arguments passed to a variadic macro in C99 or using any GCC extensions ?
For e.g. is it possible to write a generic macro that takes a structure and its fields passed as arguments and prints offset of each field within the structure ?
Something like this:
struct a {
int a;
...
[Updated organization and content for clarity]
The Real Question
What would be a good way, for C, to help a programmer, while s/he's typing, write safe and correct calls to project-specific printf-like debugging functions?
C macros?
C wrapper functions?
Code editor macros or templates?
Other?
Background Questions and Answers
Much so...
I was wondering if C++0x provides any built-in capabilities to check if a parameter pack of a variadic template contains a specific type. Today, boost:::mpl::contains can be used to accomplish this if you are using boost::mpl::vector as a substitute for variadic templates proper. However, it has serious compilation-time overhead. I suppo...
Simple question for which I could not find answer on the net. In variadic argument macros, how to find the number of arguments? I am okay with boost preprocessor, if it has the solution.
If it makes a difference, I am trying to convert variable number of macro arguments to boost preprocessor sequence, list, or array for further reproce...
Having some issues with the ... in ObjectiveC.
I'm basically wrapping a method and want to accept a nil terminated list and directly pass that same list to the method I am wrapping.
Here's what I have but it causes an EXC_BAD_ACCESS crash. Inspecting the local vars, it appears when otherButtonTitles is simply a NSString when it is pas...
is it possible to construct variadic arguments for function by overloading operator comma of the argument? i want to see an example how to do so.., maybe something like this:
template <typename T> class ArgList {
public:
ArgList(const T& a);
ArgList<T>& operator,(const T& a,const T& b);
}
//declaration
void myFunction(ArgList<in...
Here's the scenario: I'd like to have a host class that can have a variable number of mixins (not too hard with variadic templates--see for example http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.103.144). However, I'd also like the mixins to be parameterized by the host class, so that they can refer to its public types (using th...
Hi,
I'm currently experiencing with the new c++0x variadic templates, and it's quite fun, Although I have a question about the process of member instantiation.
in this example, I'm trying to emulate the strongly typed enum with the possibility of choose a random valid strong enum (this is used for unit testing).
#include<vector>
#in...
I am trying to write a generic allocator class that does not really release an object's memory when it is free()'d but holds it in a queue and returns a previously allocated object if a new one is requested. Now, what I can't wrap my head around is how to pass arguments to the object's constructor when using my allocator (at least withou...
I have something like the following code:
template<typename T1, typename T2, typename T3, typename T4>
void inc(T1& t1, T2& t2, T3& t3, T4& t4) { ++t1; ++t2; ++t3; ++t4; }
template<typename T1, typename T2, typename T3>
void inc(T1& t1, T2& t2, T3& t3) { ++t1; ++t2; ++t3; }
template<typename T1, typename T2>
void inc...
I wrote the following program
#include <iostream>
template<typename C, typename Res, typename... Args>
class bind_class_t {
private:
Res (C::*f)(Args...);
C *c;
public:
bind_class_t(Res (C::*f)(Args...), C* c) : f(f), c(c) { }
Res operator() (Args... args) {
return (c->*f)(args...);
}
};
template<typename C, typename Res,...
Hi,
I was playing around with variadic templates (gcc 4.5) and hit this problem :
template <typename... Args>
boost::tuple<Args...>
my_make_tuple(Args... args)
{
return boost::tuple<Args...>(args...);
}
int main (void)
{
boost::tuple<int, char> t = my_make_tuple(8, 'c');
}
GCC error message :
sorry, unimplemented: cannot expa...
Hi All,
Suppose I have a variadic template function like
template<typename... Args>
unsigned length(Args... args);
How do I find the length of the parameter list using the length function ?
...
I want to fill the template parameters passed to a variadic template into an array with fixed length. For that purpose I wrote the following helper function templates
template<typename ForwardIterator, typename T>
void fill(ForwardIterator i) { }
template<typename ForwardIterator, typename T, T head, T... tail>
void fill(ForwardIterato...
Is there a macro that tells me whether or not my compiler supports variadic templates?
#ifdef VARIADIC_TEMPLATES_AVAILABLE
template<typename... Args> void coolstuff(Args&&... args);
#else
???
#endif
If they are not supported, I guess I would simulate them with a bunch of overloads. Any better ideas? Maybe there are preprocessor li...