|  | Typedef Bug/Error |  | |
| | | Pranav |  |
| Posted: Mon Sep 01, 2008 5:43 pm Post subject: 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) |
| |
| | | Harald van Dijk |  |
| Posted: Mon Sep 01, 2008 5:43 pm Post subject: 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. |
| |
| | | Pranav |  |
| Posted: Mon Sep 01, 2008 6:08 pm Post subject: Re: Typedef Bug/Error |  |
On Sep 1, 10:51 pm, Harald van D©¦k <true...@gmail.com> wrote:
| Quote: | On Mon, 01 Sep 2008 10:43:54 -0700, 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.
|
K..., Here Lies The Problem.., Thank You Harald van D©¦k.., |
| |
| | | Peter Nilsson |  |
| Posted: Tue Sep 02, 2008 1:01 am Post subject: Re: Typedef Bug/Error |  |
Harald van D©¦k <true...@gmail.com> wrote:
| 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.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.
-- Peter |
| |
| | | Harald van Dijk |  |
| Posted: Tue Sep 02, 2008 2:37 am Post subject: 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. |
| |
| | | Robert Gamble |  |
| Posted: Tue Sep 02, 2008 4:47 am Post subject: Re: Typedef Bug/Error |  |
On Sep 1, 9:01 pm, Peter Nilsson <ai...@acay.com.au> wrote:
| Quote: | Harald van D©¦k <true...@gmail.com> 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, 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 |
| |
| | | Harald van Dijk |  |
| Posted: Tue Sep 02, 2008 8:44 pm Post subject: Re: Typedef Bug/Error |  |
| |  | |
On Tue, 02 Sep 2008 15:24:22 -0700, Peter Nilsson wrote:
| Quote: | Harald van Dijk <true...@gmail.com> 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"? |
| |
| | | Harald van Dijk |  |
| Posted: Tue Sep 02, 2008 10:08 pm Post subject: Re: Typedef Bug/Error |  |
| |  | |
On Tue, 02 Sep 2008 16:31:29 -0700, Peter Nilsson wrote:
| Quote: | Harald van Dijk <true...@gmail.com> wrote: Peter Nilsson wrote: Harald van Dijk <true...@gmail.com> 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. |
| |
| | | Peter Nilsson |  |
| Posted: Tue Sep 02, 2008 10:24 pm Post subject: Re: Typedef Bug/Error |  |
Harald van D©¦k <true...@gmail.com> wrote:
| 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.
-- Peter |
| |
| | | Guest |  |
| Posted: Tue Sep 02, 2008 10:31 pm Post subject: Re: Typedef Bug/Error |  |
On Sep 3, 1:24 am, Peter Nilsson <ai...@acay.com.au> wrote:
| Quote: | Harald van D©¦k <true...@gmail.com> 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.
|
intN_t is *required* to be two's complement and without padding bits. See 7.18.1.1 p 1 |
| |
| Page 1 of 2 .:. Goto page 1, 2 Next | |
|
|