Re: Finding Type of a Void Pointer

From: George (greerga@CIRCLEMUD.ORG)
Date: 11/30/97

On Sat, 29 Nov 1997, ;P wrote:

>char *find_causer_name(void *causer)
> if (!causer)
>   return "None";
> else if (causer_is_char)
>   return GET_NAME(ch);

    return GET_NAME((struct char_data *)causer);

> else if (causer_is_obj)
>   return obj->short_description;

    return ((struct obj_data *)causer)->short_description;

> else
>   return "Unknown";

>but i can't think of how to determine whether its an object or char..uh..
>any ideas?

Easiest would be to pass a flag (integer) to the function....
(ie: byte type)

The other option is to add an integer as the first variable of every
structure and then test the value of that common variable to determine what
it is.  Note that casting an object to be a character or vice versa is very

George Greer  -   | Genius may have its limitations, but stupidity | is not thus handicapped. -- Elbert Hubbard

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

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