Checking for valid t_linklist bound to symbol s_thing

Jan 16, 2008 at 10:32pm

Checking for valid t_linklist bound to symbol s_thing

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 at 1:14pm

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


Jan 18, 2008 at 1:47pm

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 at 10:43pm

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 at 4:54am

Yeah, as long as you know the object’s class name.


You must be logged in to reply to this topic.