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


Groups > comp.lang.c > #21621

Re: typedef struct

From Nomen Nescio <nobody@dizum.com>
Newsgroups comp.lang.c
Subject Re: typedef struct
References <lnipfcgi29.fsf@nuthaus.mib.org>
Message-ID <2cb01012521a81a014f9475f7f36e00a@dizum.com> (permalink)
Date 2012-06-01 10:20 +0200
Organization mail2news@dizum.com

Show all headers | View raw


Keith Thompson <kst-u@mib.org> wrote:

> Kulin <remailer@reece.net.au> writes:
> [...]
> > 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;
> >
> > This gives compilation errors. Is it possible to create a pointer to the
> > struct being defined, within the struct, using the original typedef and
> > thereby not having to code 'struct' to define the pointer?
> [snip]
> > My desire is simply to avoid having to create pointers as struct * inside
> > the structure. Other than that I would tend to agree.
> 
> Why do you want to avoid using the "struct" keyword?

If you have a struct with several self-referential pointers it looks
cluttered to have to say struct struct struct. Really no more than that.

> But if you want to use a typedef, there's no real need to use different
> identifiers for the struct tag and the typedef name.  This:
> 
>     typedef struct A A;
> 
> is perfectly valid and doesn't create any potential ambiguity.  Or at
> least use a consistent convention, like:
> 
>     typedef struct A_ A;

Thanks a lot!

Carl















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