Re: [PATCH] stat.2: fixed inode printing in example program

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Such erroneous reporting happens for inode values greater than maximum
> value which can be stored in signed long. Casting does not seem to be
> necessary here. Printing inode as unsigned long long fixes the issue.

The cast is necessary.

Relevant standard: C18 §6.5.2.2 6

Details: 'ino_t' may (and will likely) be defined as 'unsigned long'.
If you try to print an 'unsigned long' with "%llu" you will:
- have Undefined Behavior (and a warning) if 'sizeof(long) < sizeof(long
long)'.
- have a warning if 'sizeof(long) == sizeof(long long)'.

So if you want to use 'unsigned long long', you'll need to cast.

Cheers,

Alex



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux