Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Sorry for interrupt,because my mother language is not English,it maybe a little confused to read the c programming language.

Reply
Thread Tools

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

 
 
Zhang Yuan
Guest
Posts: n/a
 
      06-12-2012
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.
 
Reply With Quote
 
 
 
 
Ike Naar
Guest
Posts: n/a
 
      06-12-2012
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.
 
Reply With Quote
 
 
 
 
Zhang Yuan
Guest
Posts: n/a
 
      06-12-2012
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.

 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      06-12-2012
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
 
Reply With Quote
 
Zhang Yuan
Guest
Posts: n/a
 
      06-12-2012
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

 
Reply With Quote
 
Joe keane
Guest
Posts: n/a
 
      06-13-2012
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.
 
Reply With Quote
 
Ike Naar
Guest
Posts: n/a
 
      06-14-2012
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
1 little 2 little 3 little Kennedys dale Digital Photography 0 03-23-2008 01:03 PM
HI STEPHANIE I WAS SO GLAD T6O TALKED TO YOUR MOTHER MOTHER'S DAY WEEK END. marie ore Computer Support 11 05-23-2006 09:02 PM
Of Intrest ? Maybe Yes, Maybe No Old Gringo Computer Support 0 10-11-2004 01:35 AM
Sorry Sorry Sorry but what camera for me - Real Esate Phil Digital Photography 19 12-28-2003 05:28 PM
Some concepts (Maybe LOL maybe not...) C++ 5 08-18-2003 05:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57