public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: C99 types VS Linus types
@ 2003-07-07 12:01 Albert Cahalan
  2003-07-07 12:22 ` Matthias Andree
  2003-07-07 12:24 ` Alan Cox
  0 siblings, 2 replies; 7+ messages in thread
From: Albert Cahalan @ 2003-07-07 12:01 UTC (permalink / raw)
  To: matthias.andree, linux-kernel

Matthias Andree writes:
> On Sun, 06 Jul 2003, Albert Cahalan wrote:

>> 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?

I think you're trolling, but just in case not...

The days of non-power-of-two word sizes are
gone for normal computing. Sign-magnitude and
ones-compliment are dead too. Float is IEEE
format, possibly skipping a few costly features.
Nobody is going to go back to the old way.

It's too bad the C99 committee didn't have the
guts to make this official.

As for 128-bit...

>> 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.

There's a logrithmic/exponential thing going on.
Measuring bits isn't like measuring kB. It's log(kB),
which interacts with Moore's law to give a plain
linear need for bits. It took about 20 years to eat
through the extra bits we got with 32-bit CPUs. Now
we have twice as many bits to eat through. So that's
40 years right there. People will make do for much
longer though; notice that 8-bit was never comfy
while 32-bit was.

>> 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

Yes, that is too ugly. It's idealistic code.
Readability matters more than worrying about
something which won't happen for over 40 years,
and won't cause Y2K-style problems even then.

If I live that long, I'll need employment anyway.

Perfection is the enemy of good. In practice,
there is a difference between theory and practice.
Etc.



^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: C99 types VS Linus types
@ 2003-07-06 22:18 Albert Cahalan
  2003-07-07  1:59 ` Matthias Andree
  0 siblings, 1 reply; 7+ messages in thread
From: Albert Cahalan @ 2003-07-06 22:18 UTC (permalink / raw)
  To: bernie, vojtech, linux-kernel

Vojtech Pavlik writes:
> On Sun, Jul 06, 2003 at 07:37:26PM +0200, Bernardo Innocenti wrote:
>> On Sunday 06 July 2003 14:23, Philippe Elie wrote:

>>> 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...
>>
>>  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!



^ permalink raw reply	[flat|nested] 7+ messages in thread
* C99 types VS Linus types
@ 2003-07-06  5:03 Bernardo Innocenti
  2003-07-06 12:23 ` Philippe Elie
  0 siblings, 1 reply; 7+ messages in thread
From: Bernardo Innocenti @ 2003-07-06  5:03 UTC (permalink / raw)
  To: linux-kernel

Hello,

before a standard was set, every single OS had to come up with its
own fancy fixed-size type definitions such as DWORD, ULONG, u32,
CARD32, u_int32_t and so on.

Since C99, the C language has acquired a standard set of machine
independent types that can be used for machine independent
fixed-width declarations.

Getting rid of all non-ISO types from kernel code could be a
desiderable long-term goal. Besides the inexplicable goodness
of standards compliance, my favourite argument is that not
depending on custom definitions makes copying code from/to
other projects a little easier.

Ok, "int32_t" is a little more typing than "s32_t", but in
exchange you get it syntax hilighted in vim like built-in
types ;-)

I suggest a soft approach: trying to use C99 types as much
as possible for new code and only converting old code to
C99 when it's not too much trouble.

I hope it doesn't turn into an endless flame war... This is
just a polite suggestion.

-- 
  // Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/  http://www.develer.com/

Please don't send Word attachments - http://www.gnu.org/philosophy/no-word-attachments.html


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-07-07 12:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-07-07 12:01 C99 types VS Linus types Albert Cahalan
2003-07-07 12:22 ` Matthias Andree
2003-07-07 12:24 ` Alan Cox
  -- strict thread matches above, loose matches on Subject: below --
2003-07-06 22:18 Albert Cahalan
2003-07-07  1:59 ` Matthias Andree
2003-07-06  5:03 Bernardo Innocenti
2003-07-06 12:23 ` Philippe Elie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox