Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #21984

Re: typedef struct

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: typedef struct
Date 2012-06-08 14:31 -0400
Organization A noiseless patient Spider
Message-ID <4FD244E4.1000002@verizon.net> (permalink)
References <lnk485rg3o.fsf@nuthaus.mib.org> <FU7C4MOD41061.1321296296@reece.net.au> <jq8fuq$a7u$2@news.httrack.net> <ff2eea74-12c7-49e3-aa6a-29ac842b3dd7@googlegroups.com>

Show all headers | View raw


On 06/08/2012 01:20 PM, 张源 西北工业大学 wrote:
> On Friday, June 1, 2012 3:14:32 AM UTC+8, Xavier Roche wrote:
>> Le 31/05/2012 21:10, Kulin a écrit :
>>> What if I want to create a pointer to the struct inside the struct?
>>> typedef struct A {
>>>     A *p1;   /* not allowed */
>>>     B *p2;   /* not allowed */
>>> } B;
>>
>> Hum, why don't you first define the type incompletely ?
>>
>> typedef struct A A;
>> struct A {
>>   A *p1;
>>   A *p2;
>> };
> 
> can you explain why we can typedef incompletely?
> such as some basic implementation on computer for this incompletely typedef?
> 
> (sorry for my awful English)

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.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: typedef struct Kulin <remailer@reece.net.au> - 2012-05-31 19:10 +0000
  Re: typedef struct Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-05-31 15:14 -0400
    Re: typedef struct Nomen Nescio <nobody@dizum.com> - 2012-06-01 02:50 +0200
    Re: typedef struct 张源 西北工业大学 <zhabgyuan1993@gmail.com> - 2012-06-08 10:02 -0700
      Re: typedef struct Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-08 13:20 -0400
        Re: typedef struct 张源 西北工业大学 <zhabgyuan1993@gmail.com> - 2012-06-08 10:27 -0700
          Re: typedef struct Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-08 13:32 -0400
            Re: typedef struct 张源 西北工业大学 <zhabgyuan1993@gmail.com> - 2012-06-08 10:37 -0700
              Re: typedef struct Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-08 13:55 -0400
                Re: typedef struct Zhang Yuan <zhabgyuan1993@gmail.com> - 2012-06-08 11:22 -0700
                Re: typedef struct James Kuyper <jameskuyper@verizon.net> - 2012-06-08 14:35 -0400
                Re: typedef struct Zhang Yuan <zhabgyuan1993@gmail.com> - 2012-06-08 11:41 -0700
                Re: typedef struct Keith Thompson <kst-u@mib.org> - 2012-06-08 14:22 -0700
                Re: typedef struct Zhang Yuan <zhabgyuan1993@gmail.com> - 2012-06-08 18:28 -0700
                Re: typedef struct Zhang Yuan <zhabgyuan1993@gmail.com> - 2012-06-08 11:08 -0700
  Re: typedef struct Xavier Roche <xroche@free.fr.NOSPAM.invalid> - 2012-05-31 21:14 +0200
    Re: typedef struct 张源 西北工业大学 <zhabgyuan1993@gmail.com> - 2012-06-08 10:20 -0700
      Re: typedef struct James Kuyper <jameskuyper@verizon.net> - 2012-06-08 14:31 -0400
        Re: typedef struct Zhang Yuan <zhabgyuan1993@gmail.com> - 2012-06-08 11:45 -0700
          Re: typedef struct James Kuyper <jameskuyper@verizon.net> - 2012-06-08 15:10 -0400
            Re: typedef struct Zhang Yuan <zhabgyuan1993@gmail.com> - 2012-06-08 12:27 -0700
        Re: typedef struct Zhang Yuan <zhabgyuan1993@gmail.com> - 2012-06-08 11:48 -0700
  Re: typedef struct Keith Thompson <kst-u@mib.org> - 2012-05-31 14:24 -0700
    Re: typedef struct Nomen Nescio <nobody@dizum.com> - 2012-06-01 10:20 +0200
      Re: typedef struct Keith Thompson <kst-u@mib.org> - 2012-06-01 11:45 -0700
        Re: typedef struct Ian Collins <ian-news@hotmail.com> - 2012-06-02 07:52 +1200
        Re: typedef struct Ike Naar <ike@sverige.freeshell.org> - 2012-06-01 21:54 +0000
        Re: typedef struct "BartC" <bc@freeuk.com> - 2012-06-01 23:36 +0100
        Re: typedef struct Fritz Wuehler <fritz@spamexpire-201206.rodent.frell.theremailer.net> - 2012-06-02 23:31 +0200
          Re: typedef struct Keith Thompson <kst-u@mib.org> - 2012-06-02 18:30 -0700
        Re: typedef struct Robert Miles <milesrf@Usenet-News.net> - 2012-06-29 16:29 -0500
          Re: typedef struct Keith Thompson <kst-u@mib.org> - 2012-06-29 14:58 -0700
            Re: typedef struct Robert Miles <milesrf@Usenet-News.net> - 2012-07-01 22:55 -0500
              Re: typedef struct Keith Thompson <kst-u@mib.org> - 2012-07-01 23:00 -0700
                Re: typedef struct James Kuyper <jameskuyper@verizon.net> - 2012-07-02 07:12 -0400

csiph-web