Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Outputting u64 word using printf?

Author: Heiner Marxen

Date: 10:05:34 06/07/04

Go up one level in this thread


On June 07, 2004 at 12:08:05, Dieter Buerssner wrote:

>On June 07, 2004 at 11:11:37, Heiner Marxen wrote:
>
>>No.  I've used this kind of shifts to assert that the type "int" can contain
>>a certain amount of bits.
>
>Heiner, I agree with other things you said, but this seems not so easy possible
>in Standard C (or I don't get your idea). From the draft of the C99 Standard:
>
>---
>6.5.7 Bitwise shift operators
>Syntax
>1 shift-expression:
>additive-expression
>shift-expression << additive-expression
>shift-expression >> additive-expression
>Constraints
>2 Each of the operands shall have integer type.
>Semantics
>3 The integer promotions are performed on each of the operands. The type of the
>result is that of the promoted left operand. If the value of the right operand
>is negative or is greater than or equal to the width of the promoted left
>operand, the behavior is undefined.
>---
>
>The last sentence ...

Yes, you are right, of course.
This sentence is exactly what I was referring to,
but "I've used this kind of shifts" does in fact not be literally correct.
Sorry, Uri, for being a bit too harsh.

What I really do is shifting an initial 1u by a single bit, until it vanishes,
counting the shifted bits.

>Shifting by one less, than the width of the promoted left operand could be used,
>of course. But I would not call it "this kind of shifts" in the context of this
>discussion.

Yes, yes.  My fault.

>Wouldn't be using limits.h easier, anyway?

Well, when it is there and is reliable... yes.
So, nowadays you are right:  using "limits.h" is ok.

My programming practice with C reaches back up to the '70s,
so I still know about (and sometimes use) the pre-ANSI practices.

>Regards,
>Dieter

Cheers,
Heiner



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.