Checking for valid t_linklist bound to symbol s_thing


    Jan 16 2008 | 10:32 pm
    Paranoia dept: what would be the most reliable way to check that a non-NIL pointer bound to a symbol's s_thing field is a t_linklist?

    • Jan 18 2008 | 1:14 pm
      A common way to do this in C would be to have a 'magic number' in the linklist type, right? I don't see anything like that in the API..
      Mattijs
    • Jan 18 2008 | 1:47 pm
      You can do this like so:
      t_object *o = the_symbol->s_thing;
      if (!NOGOOD(o) && ob_sym(o) == gensym("linklist")) {
      // it's a linklist
      }
      This will test for the magic number/object validity, and then verify that it's the class you want.
    • Jan 20 2008 | 10:43 pm
      Great, thanks. I was thinking I'd need to make a custom struct containing the t_linklist and my own magic number field. So this technique is applicable to any t_object?
    • Jan 21 2008 | 4:54 am
      Yeah, as long as you know the object's class name.