Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Aug 2010 00:35:13 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no>
Cc:        src-committers@FreeBSD.org, John Baldwin <jhb@FreeBSD.org>, Takanori Watanabe <takawata@FreeBSD.org>, svn-src-all@FreeBSD.org, Bruce Evans <brde@optusnet.com.au>, svn-src-head@FreeBSD.org
Subject:   Re: svn commit: r211221 - head/usr.sbin/acpi/acpidump
Message-ID:  <20100814001308.N12943@delplex.bde.org>
In-Reply-To: <86iq3ess5a.fsf@ds4.des.no>
References:  <201008121358.o7CDwk0d098768@svn.freebsd.org> <86pqxn50vr.fsf@ds4.des.no> <4C6414A7.6020306@FreeBSD.org> <868w4bda7e.fsf@ds4.des.no> <4C643352.5010508@FreeBSD.org> <20100813200216.U12816@delplex.bde.org> <86iq3ess5a.fsf@ds4.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--0-1088411302-1281710113=:12943
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

On Fri, 13 Aug 2010, [utf-8] Dag-Erling Sm=C3=B8rgrav wrote:

> Bruce Evans <brde@optusnet.com.au> writes:
>> - `platform_class' has type uint16_t.  u_int is larger than that on all
>>   supported machines, and also on unsupported ones with 16-31 bit u_ints=
=2E
>>   Thus the cast has almost no effect, and has no effect on the result.
>
> you have to cast it to *something*, unless you're willing to assume
> blindly that uint16_t =3D=3D unsigned short (and use %h).

No, all function parameters are converted to *something*, and as I partly
explained above, the default something is always int or u_int, with the
lofical sign error for the int not causing any problems.  Various cases:
- K&R compiler, or C90-C99 compiler with no prototype in scope: integer
   parameters are converted to int or  u_int if they are smaller than that
   to start, else they are not converted.
- variadic function for a parameter after `...': same as for K&R.
- %h format for printf: makes little or no difference except for bogus
   parameters.  The parameter must end up as int or u_int after the default
   promotion.  The %h causes the parameter to be downcast to short or u_sho=
rt.
   This is different from taking a short or u_short parameter.  You just
   can't pass a short or a u_short to a variadic function,
Here uint16_t is converted to u_int on machines with 16-bit ints, else it
is converted to int.

>> Anyway, almost all typedefed types should be cast to [u]intmax_t for
>> printing, so that you don't have to know too much about what they are.
>
> long or even int is fine in many cases, e.g. uid_t, mode_t

Though it works now, it might break someday.  32-bit ino_t and printing
it with %u should have broken already.

Bruce
--0-1088411302-1281710113=:12943--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100814001308.N12943>