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


Groups > comp.lang.c > #21590 > unrolled thread

Re: typedef struct

Started byKulin <remailer@reece.net.au>
First post2012-05-31 19:10 +0000
Last post2012-07-02 07:12 -0400
Articles 15 on this page of 35 — 13 participants

Back to article view | Back to comp.lang.c

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#22001

FromZhang Yuan <zhabgyuan1993@gmail.com>
Date2012-06-08 12:27 -0700
Message-ID<1a96b982-0977-4f52-8d98-a23f2ee70e78@googlegroups.com>
In reply to#21997
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!

[toc] | [prev] | [next] | [standalone]


#21992

FromZhang Yuan <zhabgyuan1993@gmail.com>
Date2012-06-08 11:48 -0700
Message-ID<578d62b1-9a16-44f9-ae1b-390811b0bcf1@googlegroups.com>
In reply to#21984
On Saturday, June 9, 2012 2:31:00 AM UTC+8, James Kuyper wrote:
> 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.

thank you,i know a lot.
can you explain below for me?
the same representation and alignment requirements

[toc] | [prev] | [next] | [standalone]


#21602

FromKeith Thompson <kst-u@mib.org>
Date2012-05-31 14:24 -0700
Message-ID<lnipfcgi29.fsf@nuthaus.mib.org>
In reply to#21590
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?

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;

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#21621

FromNomen Nescio <nobody@dizum.com>
Date2012-06-01 10:20 +0200
Message-ID<2cb01012521a81a014f9475f7f36e00a@dizum.com>
In reply to#21602
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















[toc] | [prev] | [next] | [standalone]


#21632

FromKeith Thompson <kst-u@mib.org>
Date2012-06-01 11:45 -0700
Message-ID<ln7gvqhnw2.fsf@nuthaus.mib.org>
In reply to#21621
Nomen Nescio <nobody@dizum.com> writes:
> Keith Thompson <kst-u@mib.org> wrote:
>> Kulin <remailer@reece.net.au> writes:
[...]
>> 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.
[...]
> Carl

My question was directed to the previous poster, Kulin. Are you posting
under multiple names?

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#21633

FromIan Collins <ian-news@hotmail.com>
Date2012-06-02 07:52 +1200
Message-ID<a2skrlFll9U1@mid.individual.net>
In reply to#21632
On 06/ 2/12 06:45 AM, Keith Thompson wrote:
> Nomen Nescio<nobody@dizum.com>  writes:
>> Keith Thompson<kst-u@mib.org>  wrote:
>>> Kulin<remailer@reece.net.au>  writes:
> [...]
>>> 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.
> [...]
>> Carl
>
> My question was directed to the previous poster, Kulin. Are you posting
> under multiple names?

He or she certainly does on other groups and mail lists.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#21634

FromIke Naar <ike@sverige.freeshell.org>
Date2012-06-01 21:54 +0000
Message-ID<slrn3vfsjsiefo.dsq.ike@sverige.freeshell.org>
In reply to#21632
On 2012-06-01, Keith Thompson <kst-u@mib.org> wrote:
> Nomen Nescio <nobody@dizum.com> writes:
>> Keith Thompson <kst-u@mib.org> wrote:
>>> Kulin <remailer@reece.net.au> writes:
> [...]
>>> 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.
> [...]
>> Carl
>
> My question was directed to the previous poster, Kulin. Are you posting
> under multiple names?

Remember "George Orwell", "Borked Pseudo Mailed", "Han from China" et al. ?

[toc] | [prev] | [next] | [standalone]


#21635

From"BartC" <bc@freeuk.com>
Date2012-06-01 23:36 +0100
Message-ID<jqbg69$8hn$1@dont-email.me>
In reply to#21632
"Keith Thompson" <kst-u@mib.org> wrote in message 
news:ln7gvqhnw2.fsf@nuthaus.mib.org...
> Nomen Nescio <nobody@dizum.com> writes:
>> Keith Thompson <kst-u@mib.org> wrote:
>>> Kulin <remailer@reece.net.au> writes:
> [...]
>>> 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.
> [...]
>> Carl
>
> My question was directed to the previous poster, Kulin. Are you posting
> under multiple names?

"Nomen Nescio" said on another group that he/she uses 'anonymous remailers'. 
But with no warning that they will be using different names, and no 
signature on the posts either, things get confusing.

-- 
Bartc 

[toc] | [prev] | [next] | [standalone]


#21717

FromFritz Wuehler <fritz@spamexpire-201206.rodent.frell.theremailer.net>
Date2012-06-02 23:31 +0200
Message-ID<5610a8eaf3566e90f16f2bd77d4aefdb@msgid.frell.theremailer.net>
In reply to#21632
Keith Thompson <kst-u@mib.org> wrote:

> Nomen Nescio <nobody@dizum.com> writes:
> > Keith Thompson <kst-u@mib.org> wrote:
> >> Kulin <remailer@reece.net.au> writes:
> [...]
> >> 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.
> [...]
> > Carl
> 
> My question was directed to the previous poster, Kulin. Are you posting
> under multiple names?

No, I'm posting as myself but it gets posted through various remailers!

Thanks for the help!

Carl

[toc] | [prev] | [next] | [standalone]


#21732

FromKeith Thompson <kst-u@mib.org>
Date2012-06-02 18:30 -0700
Message-ID<lnbol1fage.fsf@nuthaus.mib.org>
In reply to#21717
Fritz Wuehler <fritz@spamexpire-201206.rodent.frell.theremailer.net>
writes:
> Keith Thompson <kst-u@mib.org> wrote:
>> Nomen Nescio <nobody@dizum.com> writes:
>> > Keith Thompson <kst-u@mib.org> wrote:
>> >> Kulin <remailer@reece.net.au> writes:
>> [...]
>> >> 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.
>> [...]
>> > Carl
>> 
>> My question was directed to the previous poster, Kulin. Are you posting
>> under multiple names?
>
> No, I'm posting as myself but it gets posted through various remailers!
>
> Thanks for the help!

Would you consider adding some consistent header line to all your posts
so we can tell it's you?

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#23006

FromRobert Miles <milesrf@Usenet-News.net>
Date2012-06-29 16:29 -0500
Message-ID<4fee1eb1$0$23463$882e7ee2@usenet-news.net>
In reply to#21632
On 6/1/2012 1:45 PM, Keith Thompson wrote:
> Keith Thompson (The_Other_Keith)kst-u@mib.org   <http://www.ghoti.net/~kst>
>      Will write code for food.
> "We must do something.  This is something.  Therefore, we must do this."
>      -- Antony Jay and Jonathan Lynn, "Yes Minister"

Looks like someone needs to answer "Pushing you out a rather high window 
is something.  Therefore, we must do that too."

[toc] | [prev] | [next] | [standalone]


#23007

FromKeith Thompson <kst-u@mib.org>
Date2012-06-29 14:58 -0700
Message-ID<ln1ukx3hnb.fsf@nuthaus.mib.org>
In reply to#23006
Robert Miles <milesrf@Usenet-News.net> writes:
> On 6/1/2012 1:45 PM, Keith Thompson wrote:
>> Keith Thompson (The_Other_Keith)kst-u@mib.org   <http://www.ghoti.net/~kst>
>>      Will write code for food.
>> "We must do something.  This is something.  Therefore, we must do this."
>>      -- Antony Jay and Jonathan Lynn, "Yes Minister"
>
> Looks like someone needs to answer "Pushing you out a rather high window 
> is something.  Therefore, we must do that too."

Any particular reason?

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#23069

FromRobert Miles <milesrf@Usenet-News.net>
Date2012-07-01 22:55 -0500
Message-ID<4ff11bee$0$26142$882e7ee2@usenet-news.net>
In reply to#23007
On 6/29/2012 4:58 PM, Keith Thompson wrote:
> Robert Miles <milesrf@Usenet-News.net> writes:
>> On 6/1/2012 1:45 PM, Keith Thompson wrote:
>>> Keith Thompson (The_Other_Keith)kst-u@mib.org   <http://www.ghoti.net/~kst>
>>>       Will write code for food.
>>> "We must do something.  This is something.  Therefore, we must do this."
>>>       -- Antony Jay and Jonathan Lynn, "Yes Minister"
>>
>> Looks like someone needs to answer "Pushing you out a rather high window
>> is something.  Therefore, we must do that too."
>
> Any particular reason?

Whoever that quote came from appears to need to think some more, and
this answer should help start that thinking.

[toc] | [prev] | [next] | [standalone]


#23070

FromKeith Thompson <kst-u@mib.org>
Date2012-07-01 23:00 -0700
Message-ID<lnk3ym1z45.fsf@nuthaus.mib.org>
In reply to#23069
Robert Miles <milesrf@Usenet-News.net> writes:
> On 6/29/2012 4:58 PM, Keith Thompson wrote:
>> Robert Miles <milesrf@Usenet-News.net> writes:
>>> On 6/1/2012 1:45 PM, Keith Thompson wrote:
>>>> Keith Thompson (The_Other_Keith)kst-u@mib.org   <http://www.ghoti.net/~kst>
>>>>       Will write code for food.
>>>> "We must do something.  This is something.  Therefore, we must do this."
>>>>       -- Antony Jay and Jonathan Lynn, "Yes Minister"
>>>
>>> Looks like someone needs to answer "Pushing you out a rather high window
>>> is something.  Therefore, we must do that too."
>>
>> Any particular reason?
>
> Whoever that quote came from appears to need to think some more, and
> this answer should help start that thinking.

Perhaps you missed the fact that the quote is intended to be humorous.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#23074

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-07-02 07:12 -0400
Message-ID<jsrvm9$8te$1@dont-email.me>
In reply to#23070
On 07/02/2012 02:00 AM, Keith Thompson wrote:
> Robert Miles <milesrf@Usenet-News.net> writes:
>> On 6/29/2012 4:58 PM, Keith Thompson wrote:
>>> Robert Miles <milesrf@Usenet-News.net> writes:
>>>> On 6/1/2012 1:45 PM, Keith Thompson wrote:
>>>>> Keith Thompson (The_Other_Keith)kst-u@mib.org   <http://www.ghoti.net/~kst>
>>>>>       Will write code for food.
>>>>> "We must do something.  This is something.  Therefore, we must do this."
>>>>>       -- Antony Jay and Jonathan Lynn, "Yes Minister"
>>>>
>>>> Looks like someone needs to answer "Pushing you out a rather high window
>>>> is something.  Therefore, we must do that too."
>>>
>>> Any particular reason?
>>
>> Whoever that quote came from appears to need to think some more, and
>> this answer should help start that thinking.
> 
> Perhaps you missed the fact that the quote is intended to be humorous.

If was clearly intended to be humorous by the real-world author.
However, was it intended to be humorous by the fictional character who
spoke that line? Having seen only a little of that show, I had assumed
that it was an expression of bureaucratic incompetence so extreme that
"Pushing you out a rather high window" would have led to a significant
improvement in government efficiency. There did seem to be several
characters on that show who could plausibly have spoken such a line
without humorous intent.
-- 
James Kuyper

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.c


csiph-web