Don't document the types of standard typedefs
Paul Eggert
eggert@cs.ucla.edu
Mon Feb 27 05:47:00 GMT 2012
On 02/26/2012 07:57 PM, Mike Frysinger wrote:
> i think it's unhelpful to encourage people to make assumptions about the sizes
> of mode_t. i've been bitten by that when i tried something naïve like:
> mode_t m;
> scanf("%u", &m);
> and %u ends up writing more bytes than mode_t is taking up on the stack.
We don't disagree about this. The manual needn't
say that mode_t is 'unsigned int', merely that (on GNU hosts)
it's an unsigned integer type that's no narrower
than 'unsigned int'. That way, application code like this:
mode_t mode = va_arg (ap, mode_t);
will work. This code doesn't necessarily work if mode_t is narrower
than int, and there's no simple and portable code that would handle
that case, so it's helpful to tell application developers that on GNU systems
they don't need to worry about that case.
> doesn't describing it as "an integer data type" handle your concerns about
> shift behavior ?
No, because signed shifting has unspecified/undefined behavior once
a sign bit is involved. Knowing that mode_t is unsigned can simplify
code that shifts mode_t values.
More information about the Libc-alpha
mailing list