Date: Wed, 03 Aug 2011 20:03:06 +0200 From: Luka Marčetić <paxcoder@...il.com> To: musl@...ts.openwall.com Subject: Re: cluts weekly reports On 08/03/2011 07:22 PM, Rich Felker wrote: >>> I'm still confused why >>> this can't be done in plain C, with the test parameters in C >>> structures that you loop over, much like some of the existing tests >>> (e.g. numeric). > Could you please give some concrete examples of what trouble you're > running into? I think you're looking for a very complex solution to a > very simple problem, but I can't know until you give me a better idea > of the specific problem. There are easy ways to handle this type of > thing, with solutions ranging from a macro that concatenates the right > type of format specifier into the message string to rolling your own > rudimentary message formatting function that takes a void pointer or > union type for the data to print. Ideally what I'd want is: fp(args) where fp is a function pointer to functions with different prototypes, and args are a number of arguments, each of an arbitrary type. Or at least: if (nr_args == 1) fp (*(type *) arg); else if (nr_args == 2) fp (*(type *) arg, *(type *) arg); What I'm doing instead essentially is: if (fp == specific_function) specific_function(*(int*)arg, *(char **)arg); else if (fp == another_function) another_function(*(size_t *)arg); I'm tired of doing that. Every time I get around to that part, not only do I need to consider pro's and con's of using function pointers vs enums vs switch-cases, but also, my first instinct is always: How do I make a generic function caller. There's no such thing in C, so I compensate. > As for function pointers and the need for different numbers and types > of arguments, you can either pass a pointer to a structure that > contains all of the argument data (thereby always having the same > function signature taking a single void * argument) or have a separate > type field and cast the function pointer to the right function type > and make the call with the right parameters based on the stored type. That just dislocates above, and puts it into the function to be called with the arg pointer (and, don't forget, the function identifier). I can go to IRC if you want to see what the generator output is/should be, and based on what input. Luka
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.