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

Alejandro Colomar
2020-09-13T18:44:04Z

> 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