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 20 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 1 of 2  [1] 2  Next page →


#21590 — Re: typedef struct

FromKulin <remailer@reece.net.au>
Date2012-05-31 19:10 +0000
SubjectRe: typedef struct
Message-ID<FU7C4MOD41061.1321296296@reece.net.au>
Keith Thompson <kst-u@mib.org> wrote:

> John McDermick <johnthedspguy@gmail.com> writes:
> > If I have this definition in a header file:
> >
> > typedef struct A
> > {
> >    int test;
> > } B;
> >
> > What exactly is A and what is B ?

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?

> struct A {
>       struct A *p;
> };


> and then refer to it as "struct A".  There's no real need to use a
> typedef to give the type another name; it already has a perfectly good
> one.
> 
> (The counterargument is that many people like to have a one-word name
> for the type.)

My desire is simply to avoid having to create pointers as struct * inside
the structure. Other than that I would tend to agree.


[toc] | [next] | [standalone]


#21591

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2012-05-31 15:14 -0400
Message-ID<jq8ftq$a51$1@dont-email.me>
In reply to#21590
On 5/31/2012 3:10 PM, Kulin wrote:
> Keith Thompson<kst-u@mib.org>  wrote:
>
>> John McDermick<johnthedspguy@gmail.com>  writes:
>>> If I have this definition in a header file:
>>>
>>> typedef struct A
>>> {
>>>     int test;
>>> } B;
>>>
>>> What exactly is A and what is B ?
>
> 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?
>
>> struct A {
>>        struct A *p;
>> };
>
>
>> and then refer to it as "struct A".  There's no real need to use a
>> typedef to give the type another name; it already has a perfectly good
>> one.
>>
>> (The counterargument is that many people like to have a one-word name
>> for the type.)
>
> My desire is simply to avoid having to create pointers as struct * inside
> the structure. Other than that I would tend to agree.

	typedef struct A B;  // "incomplete type" declaration
	struct A {           // "completes" the type `struct A'
	    int test;
	    B *p1;
	};

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

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


#21614

FromNomen Nescio <nobody@dizum.com>
Date2012-06-01 02:50 +0200
Message-ID<6bb267877085d62d22d58252aed9c4c6@dizum.com>
In reply to#21591
Thank you very much!

Carl

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


#21969

From张源 西北工业大学 <zhabgyuan1993@gmail.com>
Date2012-06-08 10:02 -0700
Message-ID<892ca144-23f4-442e-9818-b281d09dda83@googlegroups.com>
In reply to#21591
On Friday, June 1, 2012 3:14:00 AM UTC+8, Eric Sosman wrote:
> On 5/31/2012 3:10 PM, Kulin wrote:
> > Keith Thompson<kst-u@mib.org>  wrote:
> >
> >> John McDermick<johnthedspguy@gmail.com>  writes:
> >>> If I have this definition in a header file:
> >>>
> >>> typedef struct A
> >>> {
> >>>     int test;
> >>> } B;
> >>>
> >>> What exactly is A and what is B ?
> >
> > 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?
> >
> >> struct A {
> >>        struct A *p;
> >> };
> >
> >
> >> and then refer to it as "struct A".  There's no real need to use a
> >> typedef to give the type another name; it already has a perfectly good
> >> one.
> >>
> >> (The counterargument is that many people like to have a one-word name
> >> for the type.)
> >
> > My desire is simply to avoid having to create pointers as struct * inside
> > the structure. Other than that I would tend to agree.
> 
> 	typedef struct A B;  // "incomplete type" declaration

can i understand in this way:the ambiguity of struct A is B ?

> 	struct A {           // "completes" the type `struct A'
> 	    int test;
> 	    B *p1;
> 	};



> 
> -- 
> Eric Sosman
> esosman@ieee-dot-org.invalid


On Friday, June 1, 2012 3:14:00 AM UTC+8, Eric Sosman wrote:
> On 5/31/2012 3:10 PM, Kulin wrote:
> > Keith Thompson<kst-u@mib.org>  wrote:
> >
> >> John McDermick<johnthedspguy@gmail.com>  writes:
> >>> If I have this definition in a header file:
> >>>
> >>> typedef struct A
> >>> {
> >>>     int test;
> >>> } B;
> >>>
> >>> What exactly is A and what is B ?
> >
> > 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?
> >
> >> struct A {
> >>        struct A *p;
> >> };
> >
> >
> >> and then refer to it as "struct A".  There's no real need to use a
> >> typedef to give the type another name; it already has a perfectly good
> >> one.
> >>
> >> (The counterargument is that many people like to have a one-word name
> >> for the type.)
> >
> > My desire is simply to avoid having to create pointers as struct * inside
> > the structure. Other than that I would tend to agree.
> 
> 	typedef struct A B;  // "incomplete type" declaration
> 	struct A {           // "completes" the type `struct A'
> 	    int test;
> 	    B *p1;
> 	};
> 
> -- 
> Eric Sosman
> esosman@ieee-dot-org.invalid



On Friday, June 1, 2012 3:14:00 AM UTC+8, Eric Sosman wrote:
> On 5/31/2012 3:10 PM, Kulin wrote:
> > Keith Thompson<kst-u@mib.org>  wrote:
> >
> >> John McDermick<johnthedspguy@gmail.com>  writes:
> >>> If I have this definition in a header file:
> >>>
> >>> typedef struct A
> >>> {
> >>>     int test;
> >>> } B;
> >>>
> >>> What exactly is A and what is B ?
> >
> > 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?
> >
> >> struct A {
> >>        struct A *p;
> >> };
> >
> >
> >> and then refer to it as "struct A".  There's no real need to use a
> >> typedef to give the type another name; it already has a perfectly good
> >> one.
> >>
> >> (The counterargument is that many people like to have a one-word name
> >> for the type.)
> >
> > My desire is simply to avoid having to create pointers as struct * inside
> > the structure. Other than that I would tend to agree.
> 
> 	typedef struct A B;  // "incomplete type" declaration
> 	struct A {           // "completes" the type `struct A'
> 	    int test;
> 	    B *p1;
> 	};
> 
> -- 
> Eric Sosman
> esosman@ieee-dot-org.invalid

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


#21971

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2012-06-08 13:20 -0400
Message-ID<jqtc8m$rs8$1@dont-email.me>
In reply to#21969
On 6/8/2012 1:02 PM, 张源 西北工业大学 wrote:
> On Friday, June 1, 2012 3:14:00 AM UTC+8, Eric Sosman wrote:
>> On 5/31/2012 3:10 PM, Kulin wrote:
>>> [...]
>>> My desire is simply to avoid having to create pointers as struct * inside
>>> the structure. Other than that I would tend to agree.
>>
>> 	typedef struct A B;  // "incomplete type" declaration
>
> can i understand in this way:the ambiguity of struct A is B ?

     I don't know what you mean by "the ambiguity of."  The line
actually says two things:

     1) A type named `struct A' exists.  The type is "incomplete,"
meaning that there is no information about the number of bytes a
`struct A' requires or what its member elements are.  Perhaps the
code will provide such details later to "complete" the type, but
no details are available yet.

     2) `B' is an alias for `struct A'.  `B' and `struct A' can
be used interchangeably; both refer to the exact same type.  Since
`struct A' is an incomplete type, `B' is also an incomplete type
(because it is, in fact, the same type).

>> 	struct A {           // "completes" the type `struct A'
>> 	    int test;
>> 	    B *p1;
>> 	};

     These lines "complete" the `struct A' type by describing the
struct elements.  Since `struct A' is now complete, its alias `B'
is also complete: As before, `struct A' and `B' mean the same thing.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

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


#21973

From张源 西北工业大学 <zhabgyuan1993@gmail.com>
Date2012-06-08 10:27 -0700
Message-ID<de4a2de1-5e1e-4668-b64b-841c8ad4248e@googlegroups.com>
In reply to#21971
On Saturday, June 9, 2012 1:20:16 AM UTC+8, Eric Sosman wrote:
> On 6/8/2012 1:02 PM, 张源 西北工业大学 wrote:
> > On Friday, June 1, 2012 3:14:00 AM UTC+8, Eric Sosman wrote:
> >> On 5/31/2012 3:10 PM, Kulin wrote:
> >>> [...]
> >>> My desire is simply to avoid having to create pointers as struct * inside
> >>> the structure. Other than that I would tend to agree.
> >>
> >> 	typedef struct A B;  // "incomplete type" declaration
> >
> > can i understand in this way:the ambiguity of struct A is B ?
> 
>      I don't know what you mean by "the ambiguity of."  The line
> actually says two things:
> 
>      1) A type named `struct A' exists.  The type is "incomplete,"
> meaning that there is no information about the number of bytes a
> `struct A' requires or what its member elements are.  Perhaps the
> code will provide such details later to "complete" the type, but
> no details are available yet.
> 
>      2) `B' is an alias for `struct A'.  `B' and `struct A' can
> be used interchangeably; both refer to the exact same type.  Since
> `struct A' is an incomplete type, `B' is also an incomplete type
> (because it is, in fact, the same type).
> 
> >> 	struct A {           // "completes" the type `struct A'
> >> 	    int test;
> >> 	    B *p1;
> >> 	};
> 
>      These lines "complete" the `struct A' type by describing the
> struct elements.  Since `struct A' is now complete, its alias `B'
> is also complete: As before, `struct A' and `B' mean the same thing.
> 
> -- 
> Eric Sosman
> esosman@ieee-dot-org.invalid



On Saturday, June 9, 2012 1:20:16 AM UTC+8, Eric Sosman wrote:
> On 6/8/2012 1:02 PM, 张源 西北工业大学 wrote:
> > On Friday, June 1, 2012 3:14:00 AM UTC+8, Eric Sosman wrote:
> >> On 5/31/2012 3:10 PM, Kulin wrote:
> >>> [...]
> >>> My desire is simply to avoid having to create pointers as struct * inside
> >>> the structure. Other than that I would tend to agree.
> >>
> >> 	typedef struct A B;  // "incomplete type" declaration
> >
> > can i understand in this way:the ambiguity of struct A is B ?
> 
>      I don't know what you mean by "the ambiguity of."  The line
> actually says two things:
> 
>      1) A type named `struct A' exists.  The type is "incomplete,"
> meaning that there is no information about the number of bytes a
> `struct A' requires or what its member elements are.  Perhaps the
> code will provide such details later to "complete" the type, but
> no details are available yet.
> 
>      2) `B' is an alias for `struct A'.  `B' and `struct A' can
> be used interchangeably; both refer to the exact same type.  Since
> `struct A' is an incomplete type, `B' is also an incomplete type
> (because it is, in fact, the same type).
> 
> >> 	struct A {           // "completes" the type `struct A'
> >> 	    int test;
> >> 	    B *p1;
> >> 	};
> 
>      These lines "complete" the `struct A' type by describing the
> struct elements.  Since `struct A' is now complete, its alias `B'
> is also complete: As before, `struct A' and `B' mean the same thing.
> 
> -- 
> Eric Sosman
> esosman@ieee-dot-org.invalid

thanks a lot,sorry for my awful english,since i'm a Chinese.
can you exlain why the code below are forbidden ?
typedef struct A { 
    A *p1;   /* not allowed */ 
    B *p2;   /* not allowed */ 
} B; 

This gives compilation errors.

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


#21974

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2012-06-08 13:32 -0400
Message-ID<jqtcve$v5c$1@dont-email.me>
In reply to#21973
On 6/8/2012 1:27 PM, 张源 西北工业大学 wrote:
> [...]
> thanks a lot,sorry for my awful english,since i'm a Chinese.
> can you exlain why the code below are forbidden ?
> typedef struct A {
>      A *p1;   /* not allowed */

    `struct A' is the name of a type, but `A' alone is not. The compiler
has no idea at all what `p1' should point to.

>      B *p2;   /* not allowed */

    `B' means nothing (yet), because `B' has not been declared. The
compiler has no idea what `p2' should point to.

> } B;
> 
> This gives compilation errors.

    Yes.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

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


#21976

From张源 西北工业大学 <zhabgyuan1993@gmail.com>
Date2012-06-08 10:37 -0700
Message-ID<9a2b0e73-0765-422b-94a1-da6f1e798727@googlegroups.com>
In reply to#21974
On Saturday, June 9, 2012 1:32:26 AM UTC+8, Eric Sosman wrote:
> On 6/8/2012 1:27 PM, 锟斤拷源 锟斤拷锟斤拷锟斤拷业锟斤拷学 wrote:
> > [...]
> > thanks a lot,sorry for my awful english,since i'm a Chinese.
> > can you exlain why the code below are forbidden ?
> > typedef struct A {
> >      A *p1;   /* not allowed */
> 
>     `struct A' is the name of a type, but `A' alone is not. The compiler
> has no idea at all what `p1' should point to.
> 
> >      B *p2;   /* not allowed */
> 
>     `B' means nothing (yet), because `B' has not been declared. The
> compiler has no idea what `p2' should point to.
> 
> > } B;
> > 
> > This gives compilation errors.
> 
>     Yes.
> 
> -- 
> Eric Sosman
> esosman@ieee-dot-org.invalid

Thank you for your patience .I'm new to C.
Can you give me some advice?
blog or maillist?
Thank you,this is first time i contact with others in google group.I like the atmosphere here.



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


#21978

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2012-06-08 13:55 -0400
Message-ID<jqteaf$9ah$1@dont-email.me>
In reply to#21976
On 6/8/2012 1:37 PM, 张源 西北工业大学 wrote:
> [...]
> Thank you for your patience .I'm new to C.
> Can you give me some advice?
> blog or maillist?
> Thank you,this is first time i contact with others in google group.I like the atmosphere here.

    This is not "Google group;" this is Usenet. Usenet has been around since
Google's founders were three years old. Their company does many things well,
but the "Google Groups" interface to Usenet is not among their successes.

    If you are new to C, get yourself a good book. "The C Programming
Language"
by Kernighan and Ritchie is a good one if you already have experience
with other
programming languages. (It will teach you C, but will not teach you how
to write
programs.) Other books exist, some good and some not. I do not know whether
there are good C books in Chinese.

    Another useful source is the comp.lang.c Frequently Asked Questions
(FAQ)
page at <http://www.c-faq.com/>. The coverage is somewhat spotty since
it tries
to address question that arise frequently, and some answers are a little
dated.
Nonetheless, it's an excellent place to look before posting a question.

    There's also a Usenet group called "alt.comp.lang.learn.c-c++". I know
nothing about its quality or usefulness, but the title looks helpful.
There might
be some Chinese-language C groups or forums; I don't know.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

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


#21982

FromZhang Yuan <zhabgyuan1993@gmail.com>
Date2012-06-08 11:22 -0700
Message-ID<ba3df2e7-118d-4867-af71-0715b76eb735@googlegroups.com>
In reply to#21978
On Saturday, June 9, 2012 1:55:22 AM UTC+8, Eric Sosman wrote:
> On 6/8/2012 1:37 PM, 锟斤拷源 锟斤拷锟斤拷锟斤拷业锟斤拷学 wrote:
> > [...]
> > Thank you for your patience .I'm new to C.
> > Can you give me some advice?
> > blog or maillist?
> > Thank you,this is first time i contact with others in google group.I like the atmosphere here.
> 
>     This is not "Google group;" this is Usenet. Usenet has been around since
> Google's founders were three years old. Their company does many things well,
> but the "Google Groups" interface to Usenet is not among their successes.
> 
>     If you are new to C, get yourself a good book. "The C Programming
> Language"
> by Kernighan and Ritchie is a good one if you already have experience
> with other
> programming languages. (It will teach you C, but will not teach you how
> to write
> programs.) Other books exist, some good and some not. I do not know whether
> there are good C books in Chinese.
> 
>     Another useful source is the comp.lang.c Frequently Asked Questions
> (FAQ)
> page at <http://www.c-faq.com/>. The coverage is somewhat spotty since
> it tries
> to address question that arise frequently, and some answers are a little
> dated.
> Nonetheless, it's an excellent place to look before posting a question.
> 
>     There's also a Usenet group called "alt.comp.lang.learn.c-c++". I know
> nothing about its quality or usefulness, but the title looks helpful.
> There might
> be some Chinese-language C groups or forums; I don't know.
> 
> -- 
> Eric Sosman
> esosman@ieee-dot-org.invalid

Thank you.
the quality of this usenet is higher than those in china .
chinese students prefer to read american books rather than natives.
i'm reading c primer plus now.
thank you,
It's a pitty that cfaq is blocked in china. - -! 

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


#21987

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-06-08 14:35 -0400
Message-ID<4FD245D8.50208@verizon.net>
In reply to#21982
On 06/08/2012 02:22 PM, Zhang Yuan wrote:
...
> It's a pitty that cfaq is blocked in china. - -! 

What in the world? Why do they find objectionable about the cfaq? I
known that their censors are crazy, I'm just not clear on the particular
brand of craziness that produced that decision.

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


#21988

FromZhang Yuan <zhabgyuan1993@gmail.com>
Date2012-06-08 11:41 -0700
Message-ID<86aa78bb-f979-45af-9f2e-1be600d926e2@googlegroups.com>
In reply to#21987
On Saturday, June 9, 2012 2:35:04 AM UTC+8, James Kuyper wrote:
> On 06/08/2012 02:22 PM, Zhang Yuan wrote:
> ...
> > It's a pitty that cfaq is blocked in china. - -! 
> 
> What in the world? Why do they find objectionable about the cfaq? I
> known that their censors are crazy, I'm just not clear on the particular
> brand of craziness that produced that decision.

Me neither.use some software I can go to cfaq.
This is not difficult for students in china .
pitty.sometimes ,i even can't go to google group.

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


#22018

FromKeith Thompson <kst-u@mib.org>
Date2012-06-08 14:22 -0700
Message-ID<lnk3zhbisz.fsf@nuthaus.mib.org>
In reply to#21982
Zhang Yuan <zhabgyuan1993@gmail.com> writes:
> On Saturday, June 9, 2012 1:55:22 AM UTC+8, Eric Sosman wrote:
[...]
>>     Another useful source is the comp.lang.c Frequently Asked
>> Questions (FAQ) page at <http://www.c-faq.com/>. The coverage is
>> somewhat spotty since it tries to address question that arise
>> frequently, and some answers are a little dated.  Nonetheless, it's
>> an excellent place to look before posting a question.
[...]
> It's a pitty that cfaq is blocked in china. - -! 

That's surprising.

The author of the FAQ is Steve Summit <scs@eskimo.com>.  He might
be able to offer you some advice about how to obtain a copy.
(It's up to you to decide whether that's a good idea.)

-- 
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]


#22034

FromZhang Yuan <zhabgyuan1993@gmail.com>
Date2012-06-08 18:28 -0700
Message-ID<31036ab8-6804-43eb-afcf-f9a3d90b1f8f@googlegroups.com>
In reply to#22018
On Saturday, June 9, 2012 5:22:20 AM UTC+8, Keith Thompson wrote:
> Zhang Yuan <zhabgyuan1993@gmail.com> writes:
> > On Saturday, June 9, 2012 1:55:22 AM UTC+8, Eric Sosman wrote:
> [...]
> >>     Another useful source is the comp.lang.c Frequently Asked
> >> Questions (FAQ) page at <http://www.c-faq.com/>. The coverage is
> >> somewhat spotty since it tries to address question that arise
> >> frequently, and some answers are a little dated.  Nonetheless, it's
> >> an excellent place to look before posting a question.
> [...]
> > It's a pitty that cfaq is blocked in china. - -! 
> 
> That's surprising.
> 
> The author of the FAQ is Steve Summit <scs@eskimo.com>.  He might
> be able to offer you some advice about how to obtain a copy.
> (It's up to you to decide whether that's a good idea.)
> 
> -- 
> 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"

I can connect to c-faq temporally now.
I found copy in ftp://ftp.eskimo.com/u/s/scs/C-faq
thank you!  

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


#21993

FromZhang Yuan <zhabgyuan1993@gmail.com>
Date2012-06-08 11:08 -0700
Message-ID<48767508-3043-48c9-aeea-a82aa7d7be82@googlegroups.com>
In reply to#21978
On Saturday, June 9, 2012 1:55:22 AM UTC+8, Eric Sosman wrote:
> On 6/8/2012 1:37 PM, 锟斤拷源 锟斤拷锟斤拷锟斤拷业锟斤拷学 wrote:
> > [...]
> > Thank you for your patience .I'm new to C.
> > Can you give me some advice?
> > blog or maillist?
> > Thank you,this is first time i contact with others in google group.I like the atmosphere here.
> 
>     This is not "Google group;" this is Usenet. Usenet has been around since
> Google's founders were three years old. Their company does many things well,
> but the "Google Groups" interface to Usenet is not among their successes.
> 
>     If you are new to C, get yourself a good book. "The C Programming
> Language"
> by Kernighan and Ritchie is a good one if you already have experience
> with other
> programming languages. (It will teach you C, but will not teach you how
> to write
> programs.) Other books exist, some good and some not. I do not know whether
> there are good C books in Chinese.
> 
>     Another useful source is the comp.lang.c Frequently Asked Questions
> (FAQ)
> page at <http://www.c-faq.com/>. The coverage is somewhat spotty since
> it tries
> to address question that arise frequently, and some answers are a little
> dated.
> Nonetheless, it's an excellent place to look before posting a question.
> 
>     There's also a Usenet group called "alt.comp.lang.learn.c-c++". I know
> nothing about its quality or usefulness, but the title looks helpful.
> There might
> be some Chinese-language C groups or forums; I don't know.
> 
> -- 
> Eric Sosman
> esosman@ieee-dot-org.invalid

Thank you.This Usenet is more helpful than those in china.
Students in china usually read books translated from English .
I'm reading  c primer plus in Chinese.

Thank you!

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


#21592

FromXavier Roche <xroche@free.fr.NOSPAM.invalid>
Date2012-05-31 21:14 +0200
Message-ID<jq8fuq$a7u$2@news.httrack.net>
In reply to#21590
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;
};

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


#21972

From张源 西北工业大学 <zhabgyuan1993@gmail.com>
Date2012-06-08 10:20 -0700
Message-ID<ff2eea74-12c7-49e3-aa6a-29ac842b3dd7@googlegroups.com>
In reply to#21592
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)

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


#21984

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-06-08 14:31 -0400
Message-ID<4FD244E4.1000002@verizon.net>
In reply to#21972
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.

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


#21989

FromZhang Yuan <zhabgyuan1993@gmail.com>
Date2012-06-08 11:45 -0700
Message-ID<245e351e-a24c-45c7-a740-701fad5cbe61@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 .

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.



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.



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.



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 .
what do the same representation and alignment requirements mean?

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


#21997

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-06-08 15:10 -0400
Message-ID<4FD24E43.60109@verizon.net>
In reply to#21989
> 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.

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


Page 1 of 2  [1] 2  Next page →

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


csiph-web