Re: typedef struct
- From: Zhang Yuan <zhabgyuan1993@xxxxxxxxx>
- Date: Fri, 8 Jun 2012 12:27:57 -0700 (PDT)
On Saturday, June 9, 2012 3:10:59 AM UTC+8, James Kuyper wrote:
On Saturday, June 9, 2012 2:31:00 AM UTC+8, James Kuyper wrote:...
On 06/08/2012 01:20 PM, 张源 西北工业大学 wrote:
Being able to typedef incompletely is just a side effect of being able
to declare an incomplete struct type:
struct another_incomplete_type *pointer_to_incomplete_type;
The key point is that for some purposes there's no need to know the
actual type of the struct. This is feasible because the standard
requires that all pointers to structs have the same representation and
alignment requirements, so you don't need to tell the compiler the exact
type, so long as all you're doing is receiving pointers to the type, and
passing them on to other functions that do know what the exact type is..
thank you.i know a lot .
what do the same representation and alignment requirements mean?
Every C object is stored in a series of bits; except for bit-fields,
those bits usually fill up entire bytes. Every C type has an
implementation-dependent mapping which connects bit patterns to values.
That mapping is called the representation used by that type. Unsigned
integer types have a simple binary representation. C signed integers
have one of three types of representation: 1's complement, 2's
complement, and sign-magnitude. They all store positive numbers the same
way as the corresponding unsigned type, they differ only in the way they
represent negative values. The C standard imposes no requirements on the
representation of floating point types, but does say that if
__STDC_IEC_559__ is pre-defined by the implementation, the
implementation of floating point types should conform to the
requirements of annex F, which details the ways in which they are
required to conform to the requirements of IEEE/IEC 60559.
Byte ordering (bigendian, littleendian, middleendian, etc.) is also part
of the representation. The standard imposes no requirements on byte
ordering. The C standard also says nothing about how pointers are
represented. That's entirely up to the implementation. However, it does
require that, in some cases, pointers to different types must be
represented the same way.
The alignment of a type is a requirement that objects of that type be
allocated only at particular types of addresses. For instance, if an
object may only be allocated at even addresses, it has an alignment
requirement of 2. If it can only be allocated at addresses which are
integer multiples of 4, it has an alignment requirement of 4.
thank you!very useful for me!
your explanation is very explicit！
- Prev by Date: Re: Updates to the ccl
- Next by Date: Re: copy size
- Previous by thread: Re: typedef struct
- Next by thread: Re: typedef struct