Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Typedef Bug/Error

Reply
Thread Tools

Typedef Bug/Error

 
 
Peter Nilsson
Guest
Posts: n/a
 
      09-02-2008
Harald van Dk <(E-Mail Removed)> wrote:
> Peter Nilsson wrote:
> > Harald van Dk <(E-Mail Removed)> wrote:
> > > Peter Nilsson wrote:
> > > > Note that a C99 implementation with CHAR_BIT == 32
> > > > must provide uint32_t, but it need not provide
> > > > int32_t.
> > >
> > > It must provide both.
> > >
> > > 7.18.1 Integer types
> > > 1 When typedef names differing only in the absence or
> > > presence of the initial u are defined, they shall denote
> > > corresponding signed and unsigned types as described in
> > > 6.2.5; an implementation providing one of these
> > > corresponding types shall also provide the other.

> >
> > It says that if that _both_ uint32_t and int32_t exist,
> > they must be corresponding types. It does not say the
> > presence of uint32_t requires the corresponding signed
> > integer to be two's complement and without padding.

>
> I'm not seeing how you interpret the text. Could you give
> a concrete example of an implementation you believe would
> be disallowed by "an implementation providing one of these
> corresponding types shall also provide the other"?


How about I provide you with allowed implementations that
don't meet your claim...

Example 1:

CHAR_BIT == 8
sizeof(int) == 4
UINT_MAX == 4294967295
INT_MAX == 2147483647
INT_MIN == -2147483647 /* sm or 1c, not 2c */

Here, uint32_t exists as unsigned int and has a corresponding
type under 6.2.5, namely signed int. However, signed int does
not meet the criteria needed to be int32_t.

Example 2:

CHAR_BIT == 8
sizeof(int) == 4
INT_MAX == 2147483647
INT_MIN == -2147483647-1
UINT_MAX == 2147483647

Here, int32_t exists and is signed int and has a corresponding
type under 6.2.5, namely unsigned int. However unsigned int
does not meet the criteria needed to be uint32_t.

What 7.18.1 says is this that if int32_t is chosen as say
signed int, and both unsigned int and unsigned long meet all
other criteria for being uint32_t, then uint32_t must be
unsigned int. It cannot be not unsigned long because that
is not the corresponding type to int32_t/signed int under
6.2.5.

--
Peter
 
Reply With Quote
 
 
 
 
Harald van Dijk
Guest
Posts: n/a
 
      09-03-2008
On Tue, 02 Sep 2008 16:31:29 -0700, Peter Nilsson wrote:
> Harald van Dijk <(E-Mail Removed)> wrote:
>> Peter Nilsson wrote:
>> > Harald van Dijk <(E-Mail Removed)> wrote:
>> > > Peter Nilsson wrote:
>> > > > Note that a C99 implementation with CHAR_BIT == 32 must provide
>> > > > uint32_t, but it need not provide int32_t.
>> > >
>> > > It must provide both.
>> > >
>> > > 7.18.1 Integer types
>> > > 1 When typedef names differing only in the absence or presence of
>> > > the initial u are defined, they shall denote corresponding signed
>> > > and unsigned types as described in 6.2.5; an implementation
>> > > providing one of these corresponding types shall also provide the
>> > > other.
>> >
>> > It says that if that _both_ uint32_t and int32_t exist, they must be
>> > corresponding types. It does not say the presence of uint32_t
>> > requires the corresponding signed integer to be two's complement and
>> > without padding.

>>
>> I'm not seeing how you interpret the text. Could you give a concrete
>> example of an implementation you believe would be disallowed by "an
>> implementation providing one of these corresponding types shall also
>> provide the other"?

>
> How about I provide you with allowed implementations that don't meet
> your claim...


That does not help me understand your position. If they don't meet my
claim, which comes from the standard, they are not conforming
implementations, unless my claim is an incorrect interpretation. I am
trying to understand why you think it _is_ incorrect. Your examples show
why it _should be_ incorrect.
 
Reply With Quote
 
 
 
 
Peter Nilsson
Guest
Posts: n/a
 
      09-03-2008
(E-Mail Removed) wrote:
> Peter Nilsson <(E-Mail Removed)> wrote:
> > Harald van Dk <(E-Mail Removed)> wrote:
> > > 7.18.1 Integer types
> > > 1 When typedef names differing only in the absence
> > > or presence of the initial u are defined, they shall
> > > denote corresponding signed and unsigned types as
> > > described in 6.2.5; an implementation providing one
> > > of these corresponding types shall also provide the
> > > other.

> >
> > It says that if that _both_ uint32_t and int32_t exist,
> > they must be corresponding types. It does not say the
> > presence of uint32_t requires the corresponding signed
> > integer to be two's complement and without padding.

>
> intN_t is *required* to be two's complement and without
> padding bits.


Perhaps I should have been clearer. I meant the
corresponding type under 6.2.5. An int must have a
corresponding unsigned int under 6.2.5. Similarly intN_t
must have a corresponding unsigned integer type under
6.2.5. That does not imply that intN_t's corresponding
integer type under 6.2.5 meets the criteria for uintN_t.

7.18.1p1 does not say that intN_t implies the presence of
uintN_t and vice versa. It say that if both exist,
then their corresponding types under 6.2.5 must be each
other.

If only one of intN_t or uintN exist for a given N,
7.18.1p1 does not apply.

--
Peter
 
Reply With Quote
 
Robert Gamble
Guest
Posts: n/a
 
      09-03-2008
On Sep 2, 6:34 pm, Peter Nilsson <(E-Mail Removed)> wrote:
> Robert Gamble <(E-Mail Removed)> wrote:
> > Peter Nilsson <(E-Mail Removed)> wrote:
> > > Harald van Dk <(E-Mail Removed)> wrote:
> > > > Pranav wrote:
> > > > > typedef int R1;
> > > > > unsigned R1 n1;

>
> > > > typedefs are not macros. You defined R1 as a typedef
> > > > for (signed) int. You cannot make it unsigned later.

>
> > > Hence why <stdint.h> typedefs uintN_t as well as intN_t.
> > > Note that a C99 implementation with CHAR_BIT == 32 must
> > > provide uint32_t, but it need not provide int32_t.

>
> > If the implementation provides 32-bit integers without
> > padding bits and uses two's complement representation,

>
> Let's say it does. Let's suppose int32_t is signed int.
>
> > both uint32_t and int32_t must be provided,

>
> I see nothing preventing the corresponding unsigned
> int from having the range 0..INT_MAX.
>
> > otherwise neither shall be provided; in no case can
> > one be provided without the other (7.18.1p1).

>
> If both exist, they must be corresponding types. That
> does not imply that if one meets the relevant criteria
> of an exact width integer type, so must the other.


I fail to see how what you wrote above has any impact on what the
standard says:

7.18.1p1:
"When typedef names differing only in the absence or presence of the
initial u are defined,
they shall denote corresponding signed and unsigned types as described
in 6.2.5;
an implementation providing one of these corresponding types shall
also provide the other."

I don't know how this could be any clearer. This requirement was
referenced in DR 269 by Clive Feather:
"...it can be derived from the requirement to provide both or neither
of these types..."
and there was no contradictory comment in the Committee Response.

Can you provide any normative text that contradicts this?

--
Robert Gamble
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CRTP-problem: How can the base class typedef a derived class' typedef? oor C++ 0 05-20-2008 12:39 PM
java needs typedef Steve Green Java 11 03-25-2005 09:52 AM
Typedef of a template? Richard van Wegen C++ 3 07-15-2003 07:22 AM
template typedef as return type Robert A. T. Kaldy C++ 1 07-09-2003 06:25 PM
typedef enum qazmlp C++ 2 07-02-2003 11:55 AM



Advertisments