On 5 Feb, 16:38, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> InuY4sha <inuy4...@gmail.com> writes:
> > I'd like a macro or something to do something like the following
>
> The devil is often in the detail. Questions that relate to "something
> like" what you need are often a problem down the line...
>
> > int a=1,b=2,c=3;
> > char c[4];
> > memcpy(c,foo("%i%i%i",a,b,c),4)
> > printf("%s\n",c) = 123;
> > I mean how do I handle an arbitrary number of arguments in C?
>
> Ah, that is simpler. You declare (and later define) your function
> with ... after the arguments you know about (and there must be at
> least one of those):
>
> int my_printf(const char *fmt, ...);
>
> but this is only where the problems start! In C, you can't enquire
> about the types of these as yet unknown arguments, so something must
> allow your function find out. Maybe they are all the same, maybe
> there is something like a format string that implies the types... As
> I say, the devil is in the detail. An idea of what you really need to
> do would help.
>
> Macros, can be used to a very limited extent. Again, I don't want to
> explain all the possibilities because the chances are they won't apply
> in your case!
>
> --
> Ben.
The point is
1) I *need* a dbg_print function that exploit printf functionalities
(to be free to play with different behaviors in the future).. but this
could be solved with something like
#define dbg_print(x) (printf(x))
2) I'm curious about printf.. and I think that knowing the underlaying
theory before to dig into the code could save a lot of troubles...
So let's make a simple case to detail the required functionalities,
I'd like all of the arguments to be always treated as char arrays.
Btw how would I address those "void*" arguments inside the function?
Thanks for your detailed answer for now!