Go Back   Velocity Reviews > Newsgroups > C Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

C Programming - Question on structs

 
Thread Tools Search this Thread
Old 11-05-2009, 06:39 PM   #11
Default Re: Question on structs


On 2009-11-05, Tim Streater <> wrote:
> Why shouldn't I? If I'm wrong, (certainly not excluded, see above) then
> I expect I'll be corrected by those who know better.


And this is why the status-weenies are idiots. They actually can't
conceive of you doing something in order to learn or develop, but which
could result in a temporary decline in other peoples' perception of you.

Scary, huh?

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


Seebs
  Reply With Quote
Old 11-05-2009, 08:08 PM   #12
Morris Keesan
 
Posts: n/a
Default Re: Question on structs
When you write

struct foo { int bar; int baz; };

you're declaring a type, which is named "struct foo".

When you write

typedef struct { int bar; int baz; } foo;

you're declaring a type, which is named "foo".

When you write

struct { int bar; int baz; } foo;

you're declaring a variable named foo, which is a struct.

I think your confusion comes from the fact that struct types are often
declared as types, separate from declarations of variables.
--
Morris Keesan --


Morris Keesan
  Reply With Quote
Old 11-05-2009, 08:35 PM   #13
Seebs
 
Posts: n/a
Default Re: Question on structs
On 2009-11-05, Richard Heathfield <> wrote:
> Why would making a mistake result in a temporary decline in other
> people's perception of you? I don't see that at all.


That's a fascinating question, and frankly, I'm not sure I could answer it.

BUT!

Look at all the times the status weenies assert variously that people are
afraid to talk about things they don't know, afraid to answer questions,
afraid to post code for fear it might be criticized, and so on. There is
clearly a general pattern they presume, that demonstrating less-than-perfect
ability makes you look bad, so obviously, people ought to avoid doing this.

It's one of those epiphany things to realize that they genuinely think this
is a plausible motivation to ascribe to people. They really think stuff works
this way! (Perhaps more terrifying, there are large hunks of the world in
which it does to a greater or lesser extent...)

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


Seebs
  Reply With Quote
Old 11-05-2009, 08:44 PM   #14
Keith Thompson
 
Posts: n/a
Default Re: Question on structs
phaedrus <> writes:
> I've got so far as structs in re-learning C and have hit a bit of a
> wall. The online resources on the subject seem to contradict each
> other in a way that I've not seen before. There's just ONE point I'd
> like clarified, please.
>
> This is my assertion:
>
> A 'struct' in C is not actually a modularised cluster of disparate
> data. It's simply a *template* for a complex variable of type struct,
> and it is this *variable* which actually forms the modularised cluster
> of disparate data. The struct itself is just an empty shell; merely a
> *specification* for a data object. This data object is what we call a
> variable of type struct. A struct alone therefore doesn't hold any
> data; it is not like an array. Arrays can store data, structs by
> themselves don't.
>
> Have I got that right?


Not really.

I think you're getting hung up on the distinction between a *type* and
an *object* (variable) of that type.

Does the phrase "a struct" refer to a type or an object? Does the
phrase "an array" refer to a type or an object? Or, in either case,
does it refer to a value, which is yet another different thing?

I'm not going to give you a definite answer to any of those questions;
rather, I'm going to argue that they're not particularly important
questions.

Think of "array" and "struct" as adjectives, not nouns. You can have
an array type, an array object, an array value, a struct type, a
struct object, a struct value. And likewise for integers, pointers,
unions, et cetera.

(Note: I use the word "object" rather than "variable" because
it's more precise. An object is, by definition, a "region of
data storage in the execution environment, the contents of which
can represent values"; it typically, but not always, has a type
associated with it. The word "variable" is more ambiguous.
Is an object declared with "const" a variable? It can't vary,
can it? Is an object created by a call to malloc() a variable?
We don't have a name for it; some people would call it a variable,
some wouldn't. It's another way we can get hung up on terminology,
when it's the underlying concepts that are important.)

This:

struct foo { int x; int y; };

is a type declaration; it creates a struct type. This:

struct foo obj = { 10, 20 };

is an object definition; it creates an object of that type. The
*value* of that object (until you change it) is a composite value
consisting of the values of its members, 10 and 20.

Once you think of it this way, I suggest that the answers to all your
questions become fairly obvious. A struct type can be thought of
as a "template" (using the word in the English sense, not the C++
sense). As a type, it holds no data. It's a specification for a
data object; you can create arbitrarily many objects of that type.
A struct object (an object of a struct type) occupies some amount
of storage and holds some value, which may or may not change as
the program executes. And exactly the same applies to array types,
objects, and values.

Having said all that, people commonly do use "struct" and "array"
without qualification, as nouns. The phrase "a struct" can refer
to a struct object or a struct object, or even a struct value.
Likewise for "an array", though I suppose that refers more commonly
to an object rather than a type for some reason.

Most of the time, either the meaning is fairly obvious from the
context, or it doesn't matter much. If you find the unqualified
word "struct" or "array" confusing, just be more explicit, and
if someone else uses it in an unclear manner, just ask.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


Keith Thompson
  Reply With Quote
Old 11-05-2009, 09:14 PM   #15
Kenny McCormack
 
Posts: n/a
Default Re: Question on structs
In article <slrnhf6dss.bjf.usenet->,
Seebs <usenet-> wrote:
....
>It's one of those epiphany things to realize that they genuinely think this
>is a plausible motivation to ascribe to people. They really think stuff works
>this way!


Two words: Drama Queen

>(Perhaps more terrifying, there are large hunks of the world in
>which it does to a greater or lesser extent...)


Hmmm. That kinda disproves your whole thesis, don't it?



Kenny McCormack
  Reply With Quote
Old 11-05-2009, 09:49 PM   #16
Seebs
 
Posts: n/a
Default Re: Question on structs
On 2009-11-05, Kenny McCormack <> wrote:
> In article <slrnhf6dss.bjf.usenet->,
> Seebs <usenet-> wrote:
> ...
>>It's one of those epiphany things to realize that they genuinely think this
>>is a plausible motivation to ascribe to people. They really think stuff works
>>this way!


> Two words: Drama Queen


I'd agree that those words are perhaps accurate, but I was trying to be more
charitable. While thinking about relationships in terms of status does
generally lead to drama, I don't think it's usually intentional.

>>(Perhaps more terrifying, there are large hunks of the world in
>>which it does to a greater or lesser extent...)


> Hmmm. That kinda disproves your whole thesis, don't it?


Nope.

My thesis is that not everyone is completely driven by status -- in
particular, that especially among engineering sorts, you're likely to see
a lot of people who are totally unconcerned about status.

It's like culture. Cultural norms vary. That's fine. Lots of different
cultures work. What doesn't work is insisting on interpreting people's
behavior according to the rules of another culture, because that's crazy.
Imposing a status narrative on many of the posters in comp.lang.c is every
bit as stupid as trying to describe a Japanese business meeting in terms
of what the behaviors and speech acts in question would mean if they'd
been performed at a business meeting involving a bunch of Texans.

I'm not disputing that status relationships do exist in some contexts, or
that some people care about them. It's quite obvious that some people
care very deeply about them. I'm just disputing the assertion that every
relationship anywhere is necessarily about status, or even has a status
component to it. Not all do. It's only one of the many ways humans interact,
and some people don't do it. Autism's the obvious extreme case, but there
are plenty of people who are physically capable of experiencing status
relationships, but who still don't view status as a significant priority.

In short, there are a lot of people out there who would rather look bad
being right than look good being wrong. I know it may sound strange or
mysterious, but trust me, the opposite sounds just as strange to them.

But again: I've never claimed that *no* status relationships existed -- only
that not *everything* is a status relationship. If you think that
acknowledging the existence of status relationships undermines this, you
really do need to work on your basic reading comprehension skills. Maybe
you could start with the Sesame Street episode that introduces "some
of the monsters, all of the monsters, none of the monsters".

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


Seebs
  Reply With Quote
Old 11-05-2009, 10:14 PM   #17
Seebs
 
Posts: n/a
Default Re: Question on structs
On 2009-11-05, Richard Heathfield <> wrote:
>> Look at all the times the status weenies assert [...]


> Well, no thanks - I have better ways to spend my time.


I've found that a couple of hours spent saying "wait, they think WHAT?"
has been really rewarding in helping me deal with them when I have to.

It's like portability. Pays off eventually even if it's not obvious
why it should matter for a given project.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


Seebs
  Reply With Quote
Old 11-05-2009, 11:13 PM   #18
Peter Nilsson
 
Posts: n/a
Default Re: Question on structs
Seebs <usenet-nos...@seebs.net> wrote:
> Tim Streater <timstrea...@waitrose.com> wrote:
> > In the context:
> > > Why would you offer advice in group of C specialists
> > > if you only "think" that's what you used to do?

> >
> > Why shouldn't I? If I'm wrong, (certainly not excluded,
> > see above) then I expect I'll be corrected by those who
> > know better.

>
> And this is why the status-weenies are idiots. They
> actually can't conceive of you doing something in order
> to learn or develop,


Of course, we all learn through intelligent discourse,
but it's not particularly productive, educationally or
professionally, to be sloppy because you _expect_ others
to clean up after you.

'If I'm wrong people will correct me' is an attitude
that invariably places a burden on others to actually
do so. At the very least it is taking people for granted.

Asking questions is more conducive to development
than giving careless answers, whether qualified as
recollections or not.

--
Peter


Peter Nilsson
  Reply With Quote
Old 11-05-2009, 11:52 PM   #19
Seebs
 
Posts: n/a
Default Re: Question on structs
On 2009-11-05, Peter Nilsson <> wrote:
> Of course, we all learn through intelligent discourse,
> but it's not particularly productive, educationally or
> professionally, to be sloppy because you _expect_ others
> to clean up after you.


Not in general.

> 'If I'm wrong people will correct me' is an attitude
> that invariably places a burden on others to actually
> do so. At the very least it is taking people for granted.


In general, I might agree, but as it was already pointed out, Tim
went out of his way to highlight that his memory might be unreliable
in this matter.

> Asking questions is more conducive to development
> than giving careless answers, whether qualified as
> recollections or not.


If the only people giving answers are the ones who are totally certain
that they're right, we'll get a lot of very poor answers.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


Seebs
  Reply With Quote
Old 11-06-2009, 05:46 AM   #20
Barry Schwarz
 
Posts: n/a
Default Re: Question on structs
On Thu, 5 Nov 2009 03:44:39 -0800 (PST), phaedrus
<> wrote:

>Hi guys,
>
>I've got so far as structs in re-learning C and have hit a bit of a
>wall. The online resources on the subject seem to contradict each
>other in a way that I've not seen before. There's just ONE point I'd
>like clarified, please.
>
>This is my assertion:
>
>A 'struct' in C is not actually a modularised cluster of disparate
>data. It's simply a *template* for a complex variable of type struct,
>and it is this *variable* which actually forms the modularised cluster
>of disparate data. The struct itself is just an empty shell; merely a
>*specification* for a data object. This data object is what we call a
>variable of type struct. A struct alone therefore doesn't hold any
>data; it is not like an array. Arrays can store data, structs by
>themselves don't.


By that reasoning, an int does not hold a value either, only an object
of type int can hold the value.

The phrase "int" can refer to the type or to an object of that type,
depending on the context of the discussion. The same is true of
struct y.

If you want to argue that after the definition
int x;
it is incorrect to say "x is an int" but rather "x is an object of
type int", then you would be consistent saying a struct y does not
hold data, only an object of type struct y does.

I would guess that the distinction is unnecessary in 99%+ of normal
discussions.

--
Remove del for email


Barry Schwarz
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Motherboard general question Jimmy Sledge Computer Information 8 03-10-2007 08:37 AM
Question on learning "Networking"... DoubleEntendre Computer Support 15 03-11-2006 11:28 AM
hd partition question rabbit Computer Support 6 01-12-2006 04:05 AM
Wireless PEAP/MSCHAPV2 client programming question Jim Howard Wireless Networking 6 07-02-2005 12:53 PM
xp question Barry Computer Support 18 12-31-2003 06:06 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

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