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