Re: [PATCH] Re: [ipchains] logging tcp/udp port numbers

Stephen Rothwell (Stephen.Rothwell@canb.auug.org.au)
Thu, 19 Nov 1998 15:50:44 +1100 (EST)


> From: Linus Torvalds <torvalds@transmeta.com>
> Date: Thu, 19 Nov 1998 14:27:02 +1100
>
> On Wed, 18 Nov 1998, R Shapiro wrote:
> > Linus Torvalds writes:
> > > it (ie instead of using
> > >
> > > num = va_arg(args, short);
> > >
> > > it might be proper to use
> > >
> > > num = (short) va_args(args, int);
> >
> > I can't answer your other questions re: linuxppc gcc and varargs, but
> > I can verify that the second form works properly in linuxppc 2.1.127
> > (compiled with egcs 1.0-2e) while the first doesn't, at least in the
> > context of the %h directive and ip_fw.c
>
> Yes, I'm almost positive that the second version is always correct due to
> the C language rules about integer promotions.
>
> However, I also suspect that the first version really _should_ work, and
> that it really is a problem in gcc or the varargs header files that makes
> it not work.
>
> Alternatively, I'd really like to know whether maybe the C standard really
> says that you _have_ to use the second form. It's possible it does.

The C standard (my Australia version AS 3955-1991 - the same as
ISO/IEC 9899: 1990) says about va_arg: ("type" is the sencond argument
to va_arg)

If there is no actual next argument, or if "type" is not compatible with
the type of the actual next argument (as promoted according to the default
argument promotions), the behaviour is undefined.

> Basically, my worry is not so much about getting it to work, I just want
> to know that it is _guaranteed_ to work and that we won't have to look
> into this again a few years from now.

Who knows how the standards people will change inthis in us in the future. :-)

Cheers,
Stephen Rothwell
http://canb.auug.org.au/~sfr/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/