Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #22141 > unrolled thread
| Started by | Zhang Yuan <zhabgyuan1993@gmail.com> |
|---|---|
| First post | 2012-06-11 23:47 -0700 |
| Last post | 2012-06-12 08:51 -0700 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.lang.c
Sorry for interrupt,because my mother language is not English,it may be a little confused to read the c programming language. Zhang Yuan <zhabgyuan1993@gmail.com> - 2012-06-11 23:47 -0700
Re: Sorry for interrupt,because my mother language is not English,it may be a little confused to read the c programming language. Ike Naar <ike@iceland.freeshell.org> - 2012-06-12 08:04 +0000
Re: Sorry for interrupt,because my mother language is not English,it may be a little confused to read the c programming language. Zhang Yuan <zhabgyuan1993@gmail.com> - 2012-06-12 08:26 -0700
Re: Sorry for interrupt,because my mother language is not English,it may be a little confused to read the c programming language. jgk@panix.com (Joe keane) - 2012-06-13 21:07 +0000
Re: Sorry for interrupt,because my mother language is not English,it may be a little confused to read the c programming language. Ike Naar <ike@iceland.freeshell.org> - 2012-06-14 04:35 +0000
Re: Sorry for interrupt,because my mother language is not English,it may be a little confused to read the c programming language. Barry Schwarz <schwarzb@dqel.com> - 2012-06-12 08:45 -0700
Re: Sorry for interrupt,because my mother language is not English,it may be a little confused to read the c programming language. Zhang Yuan <zhabgyuan1993@gmail.com> - 2012-06-12 08:51 -0700
| From | Zhang Yuan <zhabgyuan1993@gmail.com> |
|---|---|
| Date | 2012-06-11 23:47 -0700 |
| Subject | Sorry for interrupt,because my mother language is not English,it may be a little confused to read the c programming language. |
| Message-ID | <7b7c33d0-07e6-48ba-bd4b-f947e965f9bf@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | Ike Naar <ike@iceland.freeshell.org> |
|---|---|
| Date | 2012-06-12 08:04 +0000 |
| Message-ID | <slrn3vfsjtdtvr.o50.ike@iceland.freeshell.org> |
| In reply to | #22141 |
On 2012-06-12, Zhang Yuan <zhabgyuan1993@gmail.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | Zhang Yuan <zhabgyuan1993@gmail.com> |
|---|---|
| Date | 2012-06-12 08:26 -0700 |
| Message-ID | <9e64862e-278a-4fb9-af43-0a60e8793f8e@googlegroups.com> |
| In reply to | #22144 |
On Tuesday, June 12, 2012 4:04:11 PM UTC+8, Ike Naar wrote:
> On 2012-06-12, Zhang Yuan <zhabgyuan1993@gmail.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | jgk@panix.com (Joe keane) |
|---|---|
| Date | 2012-06-13 21:07 +0000 |
| Message-ID | <jraveo$l64$1@reader1.panix.com> |
| In reply to | #22144 |
In article <slrn3vfsjtdtvr.o50.ike@iceland.freeshell.org>,
Ike Naar <ike@iceland.freeshell.org> 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.
[toc] | [prev] | [next] | [standalone]
| From | Ike Naar <ike@iceland.freeshell.org> |
|---|---|
| Date | 2012-06-14 04:35 +0000 |
| Message-ID | <slrn3vfsjtiqh2.4je.ike@iceland.freeshell.org> |
| In reply to | #22222 |
On 2012-06-13, Joe keane <jgk@panix.com> wrote:
> In article <slrn3vfsjtdtvr.o50.ike@iceland.freeshell.org>,
> Ike Naar <ike@iceland.freeshell.org> 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.
[toc] | [prev] | [next] | [standalone]
| From | Barry Schwarz <schwarzb@dqel.com> |
|---|---|
| Date | 2012-06-12 08:45 -0700 |
| Message-ID | <nfnet7hjkg0fbl59bv2a4vecfqbucf2ua7@4ax.com> |
| In reply to | #22141 |
On Mon, 11 Jun 2012 23:47:42 -0700 (PDT), Zhang Yuan
<zhabgyuan1993@gmail.com> 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
[toc] | [prev] | [next] | [standalone]
| From | Zhang Yuan <zhabgyuan1993@gmail.com> |
|---|---|
| Date | 2012-06-12 08:51 -0700 |
| Message-ID | <d96a4ce0-0d6d-4184-a530-6006caeef51b@googlegroups.com> |
| In reply to | #22166 |
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
> <zhabgyuan1993@gmail.com> 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
> <zhabgyuan1993@gmail.com> 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
> <zhabgyuan1993@gmail.com> 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web