Sorry for interrupt,because my mother language is not English,it maybe a little confused to read the

Discussion in 'C Programming' started by Zhang Yuan, Jun 12, 2012.

  1. Zhang Yuan

    Zhang Yuan Guest

    charpter6
    6.1 basic

    "The tag names this kind of structure, and can be used subsequently as a shorthand for the part of the
    declaration in braces. "

    I don't understand it well.
    I refer to some native language(Chinese) translated from English.
    just literal translation.

    Will you put up an example for me to understand it?
    Thank you.
    Forgive me for my silly request.
     
    Zhang Yuan, Jun 12, 2012
    #1
    1. Advertising

  2. Zhang Yuan

    Ike Naar Guest

    Re: Sorry for interrupt,because my mother language is notEnglish,it may be a little confused to read the c programming language.

    On 2012-06-12, Zhang Yuan <> wrote:
    > charpter6
    > 6.1 basic
    >
    > "The tag names this kind of structure, and can be used subsequently
    > as a shorthand for the part of the
    > declaration in braces. "
    >
    > I don't understand it well.
    > I refer to some native language(Chinese) translated from English.
    > just literal translation.
    >
    > Will you put up an example for me to understand it?


    They probably mean that with this type definition:

    struct S { int i; double d; };

    the declaration

    struct S x;

    can be seen as a shorthand for

    struct { int i; double d; } x;

    Indeed, both declarations will declare a variable x that is
    a struct type with an int member i and a double member d.

    But there are subtle differences. For instance, with

    struct S x;
    struct S y;

    x and y have the same type, and can be assigned to each other, like in

    x = y;

    but with

    struct S x;
    struct { int i; double d; } y;

    x and y have different types, and cannot be assigned to each other:

    x = y;

    is not allowed.
     
    Ike Naar, Jun 12, 2012
    #2
    1. Advertising

  3. Zhang Yuan

    Zhang Yuan Guest

    Re: Sorry for interrupt,because my mother language is not English,itmay be a little confused to read the c programming language.

    On Tuesday, June 12, 2012 4:04:11 PM UTC+8, Ike Naar wrote:
    > On 2012-06-12, Zhang Yuan <> wrote:
    > > charpter6
    > > 6.1 basic
    > >
    > > "The tag names this kind of structure, and can be used subsequently
    > > as a shorthand for the part of the
    > > declaration in braces. "
    > >
    > > I don't understand it well.
    > > I refer to some native language(Chinese) translated from English.
    > > just literal translation.
    > >
    > > Will you put up an example for me to understand it?

    >
    > They probably mean that with this type definition:
    >
    > struct S { int i; double d; };
    >
    > the declaration
    >
    > struct S x;
    >
    > can be seen as a shorthand for
    >
    > struct { int i; double d; } x;
    >
    > Indeed, both declarations will declare a variable x that is
    > a struct type with an int member i and a double member d.
    >
    > But there are subtle differences. For instance, with
    >
    > struct S x;
    > struct S y;
    >
    > x and y have the same type, and can be assigned to each other, like in
    >
    > x = y;
    >
    > but with
    >
    > struct S x;
    > struct { int i; double d; } y;
    >
    > x and y have different types, and cannot be assigned to each other:
    >
    > x = y;
    >
    > is not allowed.



    Thank you.Learn a lot.
     
    Zhang Yuan, Jun 12, 2012
    #3
  4. Re: Sorry for interrupt,because my mother language is not English,it may be a little confused to read the c programming language.

    On Mon, 11 Jun 2012 23:47:42 -0700 (PDT), Zhang Yuan
    <> wrote:

    >charpter6
    >6.1 basic
    >
    >"The tag names this kind of structure, and can be used subsequently as a shorthand for the part of the
    >declaration in braces. "
    >
    >I don't understand it well.
    >I refer to some native language(Chinese) translated from English.
    >just literal translation.
    >
    >Will you put up an example for me to understand it?
    >Thank you.
    >Forgive me for my silly request.


    This is from K&R II, page 128.

    The example they use is
    struct point {int x; int y;};

    In this case, the tag is the token "point" (without the quotes).

    I think the idea they are trying to explain is that if you want to
    define an object of this type, you can use
    struct point p;
    and if later you need to define another object of this type you can
    use
    struct point q;

    Compare this with what happens if the structure type has no tag, as in
    struct {int x; int y;};

    In this case, to define an object of this type you would need
    struct {int x; int y;} p;
    and for a second object
    struct {int x; int y;} q;

    If the structure type has many members, this can be quite tiresome. It
    also becomes difficult to verify that both p and q are the same type.

    So the tag "point" serves as a shorter way to specify
    "{int x; int y;}". This shorthand is available only for types that
    have tags (unions, structures, and enums).

    --
    Remove del for email
     
    Barry Schwarz, Jun 12, 2012
    #4
  5. Zhang Yuan

    Zhang Yuan Guest

    Re: Sorry for interrupt,because my mother language is not English,itmay be a little confused to read the c programming language.

    Thank you.
    I understand it well now


    On Tuesday, June 12, 2012 11:45:48 PM UTC+8, Barry Schwarz wrote:
    > On Mon, 11 Jun 2012 23:47:42 -0700 (PDT), Zhang Yuan
    > <> wrote:
    >
    > >charpter6
    > >6.1 basic
    > >
    > >"The tag names this kind of structure, and can be used subsequently as a shorthand for the part of the
    > >declaration in braces. "
    > >
    > >I don't understand it well.
    > >I refer to some native language(Chinese) translated from English.
    > >just literal translation.
    > >
    > >Will you put up an example for me to understand it?
    > >Thank you.
    > >Forgive me for my silly request.

    >
    > This is from K&R II, page 128.
    >
    > The example they use is
    > struct point {int x; int y;};
    >
    > In this case, the tag is the token "point" (without the quotes).
    >
    > I think the idea they are trying to explain is that if you want to
    > define an object of this type, you can use
    > struct point p;
    > and if later you need to define another object of this type you can
    > use
    > struct point q;
    >
    > Compare this with what happens if the structure type has no tag, as in
    > struct {int x; int y;};
    >
    > In this case, to define an object of this type you would need
    > struct {int x; int y;} p;
    > and for a second object
    > struct {int x; int y;} q;
    >
    > If the structure type has many members, this can be quite tiresome. It
    > also becomes difficult to verify that both p and q are the same type.
    >
    > So the tag "point" serves as a shorter way to specify
    > "{int x; int y;}". This shorthand is available only for types that
    > have tags (unions, structures, and enums).
    >
    > --
    > Remove del for email




    On Tuesday, June 12, 2012 11:45:48 PM UTC+8, Barry Schwarz wrote:
    > On Mon, 11 Jun 2012 23:47:42 -0700 (PDT), Zhang Yuan
    > <> wrote:
    >
    > >charpter6
    > >6.1 basic
    > >
    > >"The tag names this kind of structure, and can be used subsequently as a shorthand for the part of the
    > >declaration in braces. "
    > >
    > >I don't understand it well.
    > >I refer to some native language(Chinese) translated from English.
    > >just literal translation.
    > >
    > >Will you put up an example for me to understand it?
    > >Thank you.
    > >Forgive me for my silly request.

    >
    > This is from K&R II, page 128.
    >
    > The example they use is
    > struct point {int x; int y;};
    >
    > In this case, the tag is the token "point" (without the quotes).
    >
    > I think the idea they are trying to explain is that if you want to
    > define an object of this type, you can use
    > struct point p;
    > and if later you need to define another object of this type you can
    > use
    > struct point q;
    >
    > Compare this with what happens if the structure type has no tag, as in
    > struct {int x; int y;};
    >
    > In this case, to define an object of this type you would need
    > struct {int x; int y;} p;
    > and for a second object
    > struct {int x; int y;} q;
    >
    > If the structure type has many members, this can be quite tiresome. It
    > also becomes difficult to verify that both p and q are the same type.
    >
    > So the tag "point" serves as a shorter way to specify
    > "{int x; int y;}". This shorthand is available only for types that
    > have tags (unions, structures, and enums).
    >
    > --
    > Remove del for email




    On Tuesday, June 12, 2012 11:45:48 PM UTC+8, Barry Schwarz wrote:
    > On Mon, 11 Jun 2012 23:47:42 -0700 (PDT), Zhang Yuan
    > <> wrote:
    >
    > >charpter6
    > >6.1 basic
    > >
    > >"The tag names this kind of structure, and can be used subsequently as a shorthand for the part of the
    > >declaration in braces. "
    > >
    > >I don't understand it well.
    > >I refer to some native language(Chinese) translated from English.
    > >just literal translation.
    > >
    > >Will you put up an example for me to understand it?
    > >Thank you.
    > >Forgive me for my silly request.

    >
    > This is from K&R II, page 128.
    >
    > The example they use is
    > struct point {int x; int y;};
    >
    > In this case, the tag is the token "point" (without the quotes).
    >
    > I think the idea they are trying to explain is that if you want to
    > define an object of this type, you can use
    > struct point p;
    > and if later you need to define another object of this type you can
    > use
    > struct point q;
    >
    > Compare this with what happens if the structure type has no tag, as in
    > struct {int x; int y;};
    >
    > In this case, to define an object of this type you would need
    > struct {int x; int y;} p;
    > and for a second object
    > struct {int x; int y;} q;
    >
    > If the structure type has many members, this can be quite tiresome. It
    > also becomes difficult to verify that both p and q are the same type.
    >
    > So the tag "point" serves as a shorter way to specify
    > "{int x; int y;}". This shorthand is available only for types that
    > have tags (unions, structures, and enums).
    >
    > --
    > Remove del for email
     
    Zhang Yuan, Jun 12, 2012
    #5
  6. Zhang Yuan

    Joe keane Guest

    Re: Sorry for interrupt,because my mother language is notEnglish,it may be a little confused to read the c programming language.

    In article <>,
    Ike Naar <> wrote:
    >They probably mean that with this type definition:
    >
    > struct S { int i; double d; };
    >
    >the declaration
    >
    > struct S x;
    >
    >can be seen as a shorthand for
    >
    > struct { int i; double d; } x;


    No, it's just wrong.

    A struct defined with a tag can be referred to by the same tag, and then
    it's the same type; it's probably illegal to redefine it with the same
    tag, even if the member types and names are identical, and a struct with
    a tag will never be the same type as an anonymous struct, and neither
    will two anonymous structs be the same type.

    So that's part of the problem he's having.
     
    Joe keane, Jun 13, 2012
    #6
  7. Zhang Yuan

    Ike Naar Guest

    Re: Sorry for interrupt,because my mother language is notEnglish,it may be a little confused to read the c programming language.

    On 2012-06-13, Joe keane <> wrote:
    > In article <>,
    > Ike Naar <> wrote:
    >>They probably mean that with this type definition:
    >>
    >> struct S { int i; double d; };
    >>
    >>the declaration
    >>
    >> struct S x;
    >>
    >>can be seen as a shorthand for
    >>
    >> struct { int i; double d; } x;

    >
    > No, it's just wrong.
    >
    > A struct defined with a tag can be referred to by the same tag, and then
    > it's the same type; it's probably illegal to redefine it with the same
    > tag, even if the member types and names are identical, and a struct with
    > a tag will never be the same type as an anonymous struct, and neither
    > will two anonymous structs be the same type.


    We are in agreement.
    You more or less restate what was stated
    in the part of my post that you snipped.
     
    Ike Naar, Jun 14, 2012
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UmFlZCBTYXdhbGhh?=

    English/English DLL

    =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Oct 15, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,684
    =?Utf-8?B?UmFlZCBTYXdhbGhh?=
    Oct 16, 2005
  2. IchBin
    Replies:
    1
    Views:
    793
  3. Guest
    Replies:
    5
    Views:
    633
  4. Reinhard Glauber
    Replies:
    4
    Views:
    123
    Bodo Eing
    Jan 20, 2006
  5. Zhang Yuan

    sorry for interrupt.I need some advise.

    Zhang Yuan, Jun 13, 2012, in forum: C Programming
    Replies:
    2
    Views:
    441
    David RF
    Jun 13, 2012
Loading...

Share This Page