Varargs problem
Robert Steven Glickstein
bobg+ at andrew.cmu.edu
Sat Aug 26 07:48:24 AEST 1989
I wish to extract a variable of type "pointer to function returning int"
[(int (*) ())] from a varargs parameter list, and I can't. My function
looks like the usual:
foo(va_alist) va_dcl
{
va_list ap;
int (*fn)();
va_start(ap);
fn = va_arg(ap, int (*) ());
va_end(ap);
}
The problem, at least in my OS's implementation, is that the va_arg
macro is defined as
# define va_arg(list,mode) \
((mode *)((list += (sizeof(mode)+3)&(-4))\
-((sizeof(mode)<4)?sizeof(mode):\
(sizeof(mode)+3)&(-4))))[0]
and a typecast operator like (int (*) ()) is turned into (int (*) () *)
by the macro, on which the compiler barfs.
I might be able to do
fn = (int (*) ()) va_arg(ap, char *);
but I don't know how portable this is, and I'd like to do this in a
highly portable fashion. Any suggestions?
_______________________________
Bob Glickstein, System Designer
Information Technology Center room 220
Carnegie Mellon University
Pittsburgh, PA 15213-3890
(412) 268-6743
Internet: bobg+ at andrew.cmu.edu
UUCP: ...!harvard!andrew.cmu.edu!bobg
A total abstainer is one who abstains from everything but abstention,
and especially from inactivity in the affairs of others.
-- Ambrose Bierce, "The Devil's Dictionary"
More information about the Comp.lang.c
mailing list