struct problems

G

Guest

I have done for years. Well, understanding what people mean and not
being anal about it.

for instance even when learning C I wouldn't have written

int i;

i = 1;

int main(void)
{
<whatever>
}

because my previous programming experience made the assignment before
main() to just look "wrong"

Many professional programmers never, ever learn the CORRECT terminology

true. But experience C programmers know that they can "assign" a value
to the variable in the declaration whilst they can't "assign" to in
outside a function but not in a declaration.

I submit this becomes easier to understand if you *do*
distinguish initialisation from assignment (it becomes
even more important in C++).
since its, well, not required to be a good programmer.

I think it helps. Though one of my collegues has learnt
at least three programming languages by copy-pasteing.

One knows what
one means. I dont expect many people to agree with me.

oh, you'll find peopel who'll agree with you. I'm just
not one of them.

You seem to miss the point.

int b = 1;

It IS common vocabulary to say "Assign 1 to b".

Hence my reply about choosing language carefully when talking to people
like Bill.

"carefully" to me means using the correct (standardese) definitions.
He might even understand *why* he can't do what he was trying to do!
It made it sound like you could not initialise a variable outside a
function. The fact is you can. The FACT is that (in my experience) MOST
people would still say we "assign 1 to b" in this case.

Clearly one can not assign a recently modified variable to b later on
outside the scope of a function since the execution path does not allow
that you are ONLY in the scope of functions.

We won't agree. Call me unprofessional, dense, etc etc if you want. But
I know what someone means when they say "assign 1 to be" in the
global/module scope. I dont feign confusion.

ok, nor me. But I might correct them. And I would probably
explain the difference between initialisation and assignment
if they put code like Bill's in front of me.

Some quite smart people wrote the standard, why not use it?


--
Nick Keighley

We recommend, rather, that users take advantage of the extensions of
GNU C and disregard the limitations of other compilers. Aside from
certain supercomputers and obsolete small machines, there is less
and less reason ever to use any other C compiler other than for
bootstrapping GNU CC.
(Using and Porting GNU CC)

[last time I posted that I was subject to hail of brickbats.
Just because it's in my sig doesn't mean I agree with it ]
 
G

Guest

Keith said:
Golden California Girls said:
Keith Thompson wrote:
Richard Tobin wrote:








You have done a nice job of describing the syntax.  You haven't touched on why

because Dennis Richie designed it that way.
If you write executable code outside a function body
what does it mean? Richie chose not to give it a meaning.
I don't think this was the only way to do it but it
seems a pretty good way. And most engineering
descisions can only be "pretty good".

--
Nick Keighley

-pedantic
This option is not intended to be useful; it exists only to satisfy
pedants who would otherwise claim that GNU CC fails to support the
ANSI standard.
(Using and Porting GNU CC)
 
G

Guest

Richard the troll is correct in this case, although it's the fault of
Google Groups. There's nothing Nick can do about it except switch to a
real news service/reader or stop trying to use a .sig.

ah I was going to protest that I thought I *did* put dash dash space
 
G

Guest

[snip]
I'd prefer:
     struct cat kitty[] =
     {
       { "striper", "striped" },
       { "spook",   "black"   }
     };
because it's hard to avoid the conclusion that at some point you're
very likely to want to herd these cats as a group, rather than as
individuals (an unenviable task).

    Can you elaborate a little more if you would Richard? I see you are
using an array here.

he's creating (defining is the technical term) an array of
struct kittys. The argument is that if you need more than one
why stop at two. Richard's construct is gneralisable to any number
of items whilst everyone else has stopped at two.
 
B

Bill Cunningham

[snip]

he's creating (defining is the technical term) an array of
struct kittys. The argument is that if you need more than one
why stop at two. Richard's construct is gneralisable to any number
of items whilst everyone else has stopped at two.

Ok so you could somehow add later. Maybe in another .c file right?

Bill
 
K

Keith Thompson

Bill Cunningham said:
[snip]

he's creating (defining is the technical term) an array of
struct kittys. The argument is that if you need more than one
why stop at two. Richard's construct is gneralisable to any number
of items whilst everyone else has stopped at two.

Ok so you could somehow add later. Maybe in another .c file right?

No, you can add more by changing the size of the array.
 
K

Keith Thompson

Golden California Girls said:
Keith Thompson wrote: [big snip]
You have done a nice job of describing the syntax. You haven't
touched on why

because Dennis Richie designed it that way.
If you write executable code outside a function body
what does it mean? Richie chose not to give it a meaning.
I don't think this was the only way to do it but it
seems a pretty good way. And most engineering
descisions can only be "pretty good".

I think we have a winner.

I'm wondering what you could define it to be given that C is invoked as a
function call.

By "C", do you mean "a C program"? I suppose statements at file scope
could be executed before main() is invoked.
Keith, you can't see the forest for the trees. Come up for air, the
ink fumes off the standards documents are beginning to affect you.
:)

You asked an unclear question. A few words after the "why" would have
been helpful.
 
R

Richard Bos

Mark Wooding said:
Richard Heathfield said:
[...] at some point you're very likely to want to herd these cats as a
group, rather than as individuals (an unenviable task).

Can felines be marshalled using a catherd ray tube?

Possibly, but I would prefer a magnetron.

Richard
 
J

jameskuyper

Richard said:
(e-mail address removed) wrote: ....

That person should then switch to C++, since he's clearly not paying
enough attention to program in C.

How would that help? In C++, the same lack of attention would produce
precisely the same misinterpretation. If anything, C++ requires more
attention than C, mainly because of the possibility of overloaded
functions.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,248
Latest member
MagdalenaB

Latest Threads

Top