Mabden said:
CBFalconer said:
Mabden wrote: [...]
Structs and unions have a similar definition, so the Standards
Whores think they are the same, but in fact if they were that
similar you could, for instance make a union array. That doesn't
make sense, so that is one difference unions and structures have.
Except it does make sense, and arrays of unions are implemented
all the time. Your inexperience is showing again.
I didn't mean an array of unions. I said a union can't be used as an
array.
No, a union can't be used as an array (and I don't recall anyone
claiming otherwise). I suppose a struct can be used as an array:
struct {
int elem0;
int elem1;
int elem2;
/* etc. */
}
but it seldom makes much sense to do so. If you want an array, use an
array. If you want a union, use a union. If you want a struct, use a
struct.
I don't think you can say:
union interface {
int input;
int ouput;
} u [50];
can you?
Certainly you can. It's an array of unions. It defines a type "union
interface", and defines u as an array of 50 of them.
Here's a small program using the above declaration:
#include <stdio.h>
#include <stddef.h>
int main(void)
{
union interface {
int input;
int ouput;
} u [50];
printf("sizeof(int) = %d\n", (int)sizeof(int));
printf("sizeof(union interface) = %d\n",
(int)sizeof(union interface));
printf("offsetof(union interface, input) = %d\n",
(int)offsetof(union interface, input));
printf("offsetof(union interface, ouput) = %d\n",
(int)offsetof(union interface, ouput));
printf("sizeof u = %d\n", (int)sizeof u);
return 0;
}
And here's the output I got:
sizeof(int) = 4
sizeof(union interface) = 4
offsetof(union interface, input) = 0
offsetof(union interface, ouput) = 0
sizeof u = 200
The sizes will vary, of course, on systems where sizeof(int) != 4.
It's not at all clear to me what point you're trying to make. If
you're just arguing that structs and unions aren't the same thing,
don't bother; we all know there are significant differences between
them, and nobody here has claimed otherwise.
On a more personal note, I'm tempted to suggest that if you're going
to call people "whores" you should be more careful about the facts.
There is a certain irony in insulting people when it turns out that
they're right and you're wrong. But there are really two separate
issues here. You should be more careful of your facts (whether you're
calling people "whores" or not), and you shouldn't call people
"whores" (whether you're right about the facts or not).
Think before you post.