Re: [C in General] [DG Scripts] pointers

From: d. hall (dhall@OOI.NET)
Date: 07/17/98


// thus on Fri, 17 Jul 1998 10:31:42 -0700, Tony wrote:

> In DG Scripts, it fairly often uses code like (I don't have access to my
> code):

> typedef struct trig_data;

I'm guessing you mean something like

typedef struct trig_data trig_data;

In simple terms, think of a typedef as a "#define" or an alias.

You can replace all instances of "trig_data" with "struct trig_data"

> from what I've read, that makes it so I can go "trig_data *blah" and it
> works just the same, without the struct.

Like I said, you can consider it like a "#define", but only for types.  You
do not have to use typedef's only for structures, it just so happens that
structures are what they are normally used for.

> However, now we see stuff like:

> trig_data **trg_index;

> struct trig_data **trig_index;

These are equivalent based upon the typedef above.

If you replace the lone trig_data with 'struct trig_data' you'll see how
they are the same.

Both of these defined a pointer to pointer to a struct trig_data.  Normally
you would use this to make an array of pointers to struct trig_data.  An
easy visualization of "a pointer to a pointer" is a 2 dimensional array.
This is an over-simplication of the fact.

d.


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST