Re: typedef struct



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 incomplete_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!
.



Relevant Pages

  • Re: About casts (and pointers)
    ... >> differing lengths have the same representation. ... p26, pointers to compatible types ... shall have the same representation and alignment requirements. ... requirements as 'int ', ...
    (comp.lang.c)
  • Re: two dimensional arrays:
    ... | 27 A pointer to void shall have the same representation and alignment ... Similarly, pointers ... | the same representation and alignment requirements as each other. ...
    (comp.lang.c)
  • Re: typedef struct
    ... to declare an incomplete struct type: ... 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 ... what do the same representation and alignment requirements mean? ...
    (comp.lang.c)
  • Re: what about memset?
    ... manipulate void* so that it would be a char* or int*. ... A pointer to void shall have the same representation and alignment ... pointers to qualified or unqualified versions of compatible types ... shall have the same representation and alignment requirements. ...
    (comp.lang.c)
  • Re: Trap representation
    ... space is initialized [by calloc] to all bits zero", ... representation of floating-point zero or a null pointer constant". ... pointers on the DS9K, although of course MMV on real implementations. ... if the struct contains a pointer. ...
    (comp.lang.c)