struct layout

N

Nick Keighley

please leave attributions in



this is gibberish. What is a "lay-user"? In what circumstances is an
array more efficient than a struct? I find sequential numbers easy to
remember. Use arrays when you want a series of entries of identical
type and semantics. Use structs when the type or semantics of the
contained items is disparate.

*do you remember IP addressess or names of sites* ?

this is a daft analogy. structs do not incur a name lookup at
run time. arrays and structs address different problems. If
I want to lookup infomation about the 7th transceiver then I
use an array.
in this context array is more efficient.

no. Your analogy is broken.
when was the last time you used indexes to get the members of a struct like
this:

switch(i) {
case 0: {
/* access first member */
int i = s1.m1;

break;
}

case 1: {
int i = s1.m2;

}

default: {
/* struct does not have such a member */

}

}

never.

If you want a struct, then use a struct!

the problem is: to provide the user *names* instead of indxes.

I don't see the problem

but a lot can. So called packed structs cannot even be implemented on
some architectures. What "problem" does a "packed struct" solve? You could
you use portable C to pack and unpack structs if you really need to save
space.

im aware. but a packed struct will all similar elements can be (AFAIK)

sorry I don't understand that
 
N

Nick Keighley

*do you remember IP addressess or names of sites* ? in this context array is
more efficient.
when was the last time you used indexes to get the members of a struct like
this:

switch(i) {
case 0: {
/* access first member */
int i = s1.m1;

break;
}

case 1: {
int i = s1.m2;

}

default: {
/* struct does not have such a member */

}

}

ok, if we are submitting daft code. When was the last time you used
names
to access an array?


int a [3];

int name_table[] = {"red", "blue", "green"};

int lookup_array_by_name (cont char *name)
{
for (i = 0; i < 3; i++)
if (strcmp (name, name_table) == 0)
return a ;

exit (EXIT_FAILURE);
}

<snip>
 
R

Ravishankar S

*do you remember IP addressess or names of sites* ? in this context
array is
more efficient.
when was the last time you used indexes to get the members of a struct like
this:

switch(i) {
case 0: {
/* access first member */
int i = s1.m1;

break;
}

case 1: {
int i = s1.m2;

}

default: {
/* struct does not have such a member */

}

}

ok, if we are submitting daft code. When was the last time you used
names
to access an array?


int a [3];

int name_table[] = {"red", "blue", "green"};

int lookup_array_by_name (cont char *name)
{
for (i = 0; i < 3; i++)
if (strcmp (name, name_table) == 0)
return a ;

exit (EXIT_FAILURE);
}

<snip>


Quite right. They are daft code, both. (and that proves why its easy to
solve by type casting the packed struct into array pointer). You dont see
the problem since you may have not read previous posts.

Just for info:
Its solved anyway in a different way, than I expected so that end it.
 
A

Army1987

Your copy of Outlook Express is miss-behaving. I've seen it happen
before to others so I don't blame you for this. Each level of quoted
material should have another '>' in front of it. E.g.

Bill said
My reply to Fred and Bill.

Normally OE does this, but sometimes it needs a good kicking. I don't
use it myself so I don't know where to kick.
When I used it the only solution I could find was adding > signs
myself. After a while it *did* automagically fix itself, though.
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top