delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/25/17:07:27

Message-Id: <m0xPDN5-0007qiC@fwd01.btx.dtag.de>
Date: Sat, 25 Oct 1997 23:03:47 +0200
To: joshuahab AT aol DOT com, djgpp AT delorie DOT com
References: <19971023043001 DOT AAA27550 AT ladder02 DOT news DOT aol DOT com>
Subject: Re: structures and structure pointers
MIME-Version: 1.0
From: Georg DOT Kolling AT t-online DOT de (Georg Kolling)

Joshua Hab schrieb:
> I have a couple of questions regarding structures and structure pointers...
>
> 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;
> }
/* here's a semicolon missing... */ ;

>
> typedef struct SPRITE
> {
>     int x, y, color;
> }
/* here again */ ;
This one does exactly nothing...
you should use: typedef <data type> <new name>, the new name's missing here
typedef gives a data type a new name, for example:
'typedef unsigned int uint;' makes 'uint' equvalent to 'unsigned int'
'typedef struct SPRITE
 {
  int x, y, color
 } NewNameForStructSPRITE;' makes 'NewNameForStructSPRITE' equivalent to 'struct
 SPRITE'


>
> 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.

example:

struct sprite Sprite;
struct sprite *pointer_to_Sprite = &Sprite;

Sprite.x = 1;
pointer_to_Sprite->y = 1;


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019