First I was looking for a way to declare a struct like the following:
struct obj_data *tempname[];
now I HAVE done this. It is possible but I changed it recently to get
rid of a mismatch in declaration but that crashed it rather than fixed
it so I decided to go with the 2 warnings and have it just work. But I
forgot how I did it and backed up just after I changed it <DOH>. I know
how import arrays, structs and pointers are in c and c++ and I do
understand them but my book never said anything on defining an array of
struct with the [] prefix. Thanks for your help. It did help. I ended up
putting a cap limit on it like struct obj_data *tempname[100];
Anyways thankyou everybody for your help.
- Matt
Bill Long wrote:
>
> Not sure if i understand what you are wanting. but here is just a little more
> info.
> lets say you have a struct declared as so..
> struct my_kewl_struct_type {
> char
> fname[12],
> mname[12],
> lname[12];
> int
> age,
> weight;
> } kewl_struct;
>
> you have but two ways you can declare an array of these fellas.
> the first is statically:
> struct kewl_struct mks[20];
> which will give you a fixed size array of structs. even if they are all empty.
> You can also declare an array of POINTERS to the struct and then create/destroy
> the structs as you need them. like so...
> struct kewl_struct *mks_ptr[20]; //allocate an array of POINTERS(not structs)
>
> CREATE(mks_ptr[10], struct kewl_struct, 1); //the CREATE macro is a fancy
> //calloc with error checking
> //the above will create a struct kewl_struct at the 11th position in the
> //mks_ptr array(i know..this is KINDOF dynamic..)
> free(mks_ptr[10]); //frees the space allocated for the struct but the
> //pointer is still there(it was declared statically)
>
> the second is dynamically.
>
> struct kewl_struct *first_kewl_struct;
>
> CREATE(first_kewl_struct, struct kewl_struct, 1);
> //this creates a reference to ONE structure of type kewl_struct complete
> //with allocated populating space.( achieves same result as
> //struct kewl_struct first_kewl_struct (only with different ways of
> accessing
> //the structure.
>
> CREATE(first_kewl_struct, struct kewl_struct, 20);
> //this creates a reference to MANY structures of type kewl_struct complete
> //with allocated populating space. but you must use POINTER arithmetic or
> //array notation to get to the other ones. ie (first_kewl_struct + 5) will
> //get you to the structure in the 6th position of the of the array.(i'll
> //calle it a table) or first_kewl_struct[5] (achieves the same result)
>
> i'm pretty sure that these are the only ways to declare arrays(sure, there are
> variations). i hope this helps a bit. i would also recommend that you really
> spend some bucks and get a C book. Pointers are one of the foundations of the C
> language. if you dont understand them you will spend literally HOURS sifting
> through code trying to understand what is going on.
>
> also, double check this against your books, i dont have any in front of me right
>
> now so this is all from memory, there are probable errors.
>
> Jourge Fuzz Bush wrote:
>
> > No. There is quite a difference from what george wrote and what I was
> > looking for. I will admit I didn't understand it fully (the create). But
> > after taking a look at the code for the create macro there arose to many
> > problems that a simple static array would fix. I was looking for an
> > answer that did not require me to "explicitly" define the size because I
> > didn't really want to put a cap limit on the number of people who can
> > die without reclaiming there bodybags and I didn't want to waist memory
> > that wasn't used. But I guess I will have to write some clean-up
> > procedures based on time of death and time on the mud. I think I even
> > did try defining the size of the array "explicity" but it didn't work. I
> > must have messed it up somewhere along the line. But thankyou everyone
> > for your help.
> >
>
> bill
>
> +------------------------------------------------------------+
> | Ensure that you have read the CircleMUD Mailing List FAQ: |
> | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
> +------------------------------------------------------------+
+------------------------------------------------------------+
| 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