Mail Archives: djgpp-workers/2001/08/04/07:37:16
> Date: Sat, 04 Aug 2001 10:41:29 +0100
> From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
>
> 'ls' casts st_size to an unsigned type - uintmax_t - which is defined to
> be unsigned long long:
>
> if (S_ISCHR (f->stat.st_mode) || S_ISBLK (f->stat.st_mode))
> sprintf (p, "%3u, %3u ", (unsigned) major (f->stat.st_rdev),
> (unsigned) minor (f->stat.st_rdev));
> else
> {
> char hbuf[LONGEST_HUMAN_READABLE + 1];
> sprintf (p, "%8s ",
> human_readable ((uintmax_t) f->stat.st_size, hbuf, 1,
> output_block_size < 0 ? output_block_size :
> 1));
> }
>
> This cast does not work. This seems strange - I would expect a cast from
> signed long to unsigned long long to work. Wouldn't the value be
> zero-extended to fill the unsigned long long? Does anyone have any
> suggestions on how I can fix this? (I don't have any of my C reference
> material here.) Typecasting to unsigned long then uintmax_t seems to work,
> but I think that's a hack rather than the solution.
Going through unsigned long would be something I'd suggest as well.
I'm not enough of a language lawyer to say whether this is a GCC bug.
- Raw text -