Re: undefine_c_func (was: memory profiling)
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Nov 21, 2006
- 621 views
On Mon, 20 Nov 2006 05:32:34 -0800, Chris Bensler <guest at RapidEuphoria.com> wrote: >There is no need for these kinds of hacks, Oh/Uh? >variadic functions are fairly simple to interface with once you know how. >I'm mostly going from memory and a lack of available informaton, but.. OK, I'm listening... > >All the params are stored as an array of INT's or DOUBLES, depending on the >actual type of the argument. Types are promoted, so char/short -> INT and float >-> DOUBLE That is not at all what I was taught.[1] > >It is the function's responsibility to know what the types of the arguments are >supposed to be and how many. Nor that[2] > >Eg printf's first argument is a format string which inherently specifies the >types of the variable arguments via the format flags. Nor that[3] > <snip> > >Here is a code example to give you an idea >(untested/pseudo code, I doubt it will actually work, OK, gauntlet down. Make it work. I claim you will not be able to. I'll accept a reasonable forfeit should you prove me wrong, of course /only/ if you can do so with /less/ "hacks" than the wee sequence of define_c_proc results I proposed, and keep say 60% of the code you posted? Regards, Pete [1] Far as I know, in most languages (not Eu, of course), parameters are pushed onto the stack, and the stack is kept machine-word aligned by default. There's no "array" involved, though they do end up next to each other by the time the function sees them. [2] It is NOT a mandate that a (C) function must crash when passed arguments of the wrong type. Any "responsibility" clearly lies with the caller, not the callee. [3] Clearly printf will print rubbish, and/or ignore excess arguments. Inherently it has /no/ type checking abilities. Quite how one might print 0 when you 0-terminate this fictional array is a mystery to me.