Skip to contentSkip to conversation

C99 types VS Linus types

DISCUSSION Albert Cahalan 2 participants 2 messages Jul 6, 2003 – Jul 7, 2003

lore
Share & tools
lore
#0 lore raw
Quoted 10 lines · Vojtech Pavlik
Quoted 9 lines · Bernardo Innocenti
Quoted 2 lines · Philippe Elie

alpha user space .h define uint64_t as unsigned long, include/asm-alpha/types.h defines it as unsigned long long.

Why is that? Isn't uint64_t supposed to be _always_ a 64bit unsigned integer? Either the kernel or the user space might be doing the wrong thing...

Quoted 6 lines
Quoted 2 lines

I've Cc'd the Alpha mantainer to make him aware of this
problem.

I suppose both an 'unsigned long' and 'unsigned long long' are 64-bit entities on the Alpha (which is a 64-bit architecture).

Sure, both are "correct", but there would be a lot less pain and suffering in the world if "unsigned long long" would be used for 64-bit. It ought to be at least 40 years before 128-bit types begin to matter. In the Linux world, we can consider "long long" to be 64-bit, "int" to be 32-bit, and "long" to be the same size as a pointer.

Then we can ditch the nasty casts:
sprintf(foo, "%llu", (unsigned long long)bar);

This leaves only Win64, Win16, DOS, and ELKS out in the cold. Like we should care for kernel & glibc!

#1 lore raw
Quoted 3 lines · Albert Cahalan

Sure, both are "correct", but there would be a lot less pain and suffering in the world if "unsigned long long" would be used for 64-bit.

What if unsigned long long is 96 bit? or 128?

Quoted 2 lines

It ought to be at least 40 years
before 128-bit types begin to matter.

Yup, and 8-Bit CPU and 640 kB RAM ought to be enough for...

nevermind.

Quoted 6 lines

In the Linux world,
we can consider "long long" to be 64-bit, "int" to be 32-bit, and "long" to be the same size as a pointer.

Then we can ditch the nasty casts:
sprintf(foo, "%llu", (unsigned long long)bar);

Speaking of shifting forward to standards:

unsigned char foo = 42;
char bar[42];
sprintf(bar, "%ju", (uintmax_t)foo); // see IEEE Std 1003.1-2001

If that's too ugly, write your own [u]intmax_t-to-char[] converter, then only the stack is nasty if uintmax_t is 128 bits wide and you're printing an array uint8_t. :-P

Signature · 1 line
Matthias Andree