Mail Archives: djgpp/1997/10/26/00:18:01
Joshua Hab wrote:
> First, what's the difference between a regular structure and a typedef
> structure? For example, what would be the difference between these two:
>
> struct sprite
> {
> int x, y, color;
> }
>
> typedef struct SPRITE
> {
> int x, y, color;
> }
Well, these aren't complete, for one.
In C or C++, you can write:
typedef struct S { /* ... */ } S;
which allows you to refer to this struct as either `struct S' or just
`S'.
C++ does away with the need for the struct keyword when referencing the
type, so you can just write
struct S { /* .... */ };
and you'll be able to reference it as either `struct S' or `S'. In C,
the above definition could only be referred to as `struct S'; `S' would
give an error.
> Secondly, how exactly does the -> operator work? How is it different
> from the
> '.' operator? I've know it has something to do with structure
> pointers, but
> I'm still baffled, I'd really appreciate some direction. :-) Thanks
> in advance.
The -> operator is used when the left operand is a pointer to a
structure, rather than a structure itself. That is:
struct S { int x, y, z; };
S s = { 1, 2, 3 };
int x = s.x;
S *sp = &s;
int y = s->y;
Writing a->b is exactly the same as writing (*a)->b -- it is a
convenient notation.
--
Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
Alcyone Systems / http://www.alcyone.com/max/
San Jose, California, United States / icbm://+37.20.07/-121.53.38
\
"After each war there is a little / less democracy to save."
/ Brooks Atkinson
- Raw text -