Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old September 1st, 2008, 06:45 PM
Pranav
Guest
 
Posts: n/a
Default Typedef Bug/Error

#include<stdio.h>
int main()
{
typedef int R1;
typedef int R2;
typedef long int R3;

unsigned R1 n1;
long R2 n2;
R3 n3;

n1=123456789;
n2=123456789;
n3=123456789;
printf("%u..%d\n",n1,sizeof(n1));
printf("%ld..%d\n",n2,sizeof(n2));
printf("%ld..%d\n",n3,sizeof(n3));
return 0;
}

Getting Following Errors..,
Teast2.c syntax error before "n1"
Teast2.c syntax error before "n2"
Teast2.c `n1' undeclared (first use in this function)
Teast2.c `n2' undeclared (first use in this function)

  #2  
Old September 1st, 2008, 06:55 PM
Harald van =?UTF-8?b?RMSzaw==?=
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

On Mon, 01 Sep 2008 10:43:54 -0700, Pranav wrote:
Quote:
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.
  #3  
Old September 1st, 2008, 07:15 PM
Pranav
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

On Sep 1, 10:51 pm, Harald van D©¦k <true...@gmail.comwrote:
Quote:
On Mon, 01 Sep 2008 10:43:54 -0700, Pranav wrote:
Quote:
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.
K..., Here Lies The Problem.., Thank You Harald van D©¦k..,
  #4  
Old September 2nd, 2008, 02:05 AM
Peter Nilsson
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

Harald van D©¦k <true...@gmail.comwrote:
Quote:
Pranav wrote:
Quote:
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.htypedefs 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.

--
Peter
  #5  
Old September 2nd, 2008, 05:45 AM
Harald van =?UTF-8?b?RMSzaw==?=
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

On Mon, 01 Sep 2008 18:01:04 -0700, Peter Nilsson wrote:
Quote:
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.
  #6  
Old September 2nd, 2008, 05:55 AM
Robert Gamble
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

On Sep 1, 9:01 pm, Peter Nilsson <ai...@acay.com.auwrote:
Quote:
Harald van D©¦k <true...@gmail.comwrote:
>
Quote:
Pranav wrote:
Quote:
typedef int R1;
unsigned R1 n1;
>
Quote:
typedefs are not macros. You defined R1 as a typedef
for (signed) int. You cannot make it unsigned later.
>
Hence why <stdint.htypedefs 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, both uint32_t and int32_t
must be provided, otherwise neither shall be provided; in no case can
one be provided without the other (7.18.1p1).

--
Robert Gamble
  #7  
Old September 2nd, 2008, 11:25 PM
Peter Nilsson
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

Harald van D©¦k <true...@gmail.comwrote:
Quote:
Peter Nilsson wrote:
Quote:
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.

--
Peter
  #8  
Old September 2nd, 2008, 11:35 PM
vippstar@gmail.com
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

On Sep 3, 1:24 am, Peter Nilsson <ai...@acay.com.auwrote:
Quote:
Harald van D©¦k <true...@gmail.comwrote:
>
Quote:
Peter Nilsson wrote:
Quote:
Note that a C99 implementation with CHAR_BIT == 32 must
provide uint32_t, but it need not provide int32_t.
>
Quote:
It must provide both.
>
Quote:
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.
See 7.18.1.1 p 1
  #9  
Old September 2nd, 2008, 11:35 PM
Peter Nilsson
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

Robert Gamble <rgambl...@gmail.comwrote:
Quote:
Peter Nilsson <ai...@acay.com.auwrote:
Quote:
Harald van D©¦k <true...@gmail.comwrote:
Quote:
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.htypedefs 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.
Quote:
both uint32_t and int32_t must be provided,
I see nothing preventing the corresponding unsigned
int from having the range 0..INT_MAX.
Quote:
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.

--
Peter
  #10  
Old September 2nd, 2008, 11:45 PM
Harald van =?UTF-8?b?RMSzaw==?=
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

On Tue, 02 Sep 2008 15:24:22 -0700, Peter Nilsson wrote:
Quote:
Harald van Dijk <true...@gmail.comwrote:
Quote:
>Peter Nilsson wrote:
Quote:
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"?
  #11  
Old September 3rd, 2008, 12:35 AM
Peter Nilsson
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

Harald van D©¦k <true...@gmail.comwrote:
Quote:
Peter Nilsson wrote:
Quote:
Harald van D©¦k <true...@gmail.comwrote:
Quote:
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
  #12  
Old September 3rd, 2008, 01:15 AM
Harald van =?UTF-8?b?RMSzaw==?=
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

On Tue, 02 Sep 2008 16:31:29 -0700, Peter Nilsson wrote:
Quote:
Harald van Dijk <true...@gmail.comwrote:
Quote:
>Peter Nilsson wrote:
Quote:
Harald van Dijk <true...@gmail.comwrote:
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.
  #13  
Old September 3rd, 2008, 01:15 AM
Peter Nilsson
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

vipps...@gmail.com wrote:
Quote:
Peter Nilsson <ai...@acay.com.auwrote:
Quote:
Harald van D©¦k <true...@gmail.comwrote:
Quote:
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
  #14  
Old September 3rd, 2008, 01:35 AM
Robert Gamble
Guest
 
Posts: n/a
Default Re: Typedef Bug/Error

On Sep 2, 6:34 pm, Peter Nilsson <ai...@acay.com.auwrote:
Quote:
Robert Gamble <rgambl...@gmail.comwrote:
Quote:
Peter Nilsson <ai...@acay.com.auwrote:
Quote:
Harald van D©¦k <true...@gmail.comwrote:
Pranav wrote:
typedef int R1;
unsigned R1 n1;
>
Quote:
Quote:
typedefs are not macros. You defined R1 as a typedef
for (signed) int. You cannot make it unsigned later.
>
Quote:
Quote:
Hence why <stdint.htypedefs 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.
>
Quote:
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.
>
Quote:
both uint32_t and int32_t must be provided,
>
I see nothing preventing the corresponding unsigned
int from having the range 0..INT_MAX.
>
Quote:
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
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles