Missing typeof operator


#1

Hi

Since theres no typeof operator, how do i find the type of something?

My problem is that i use the wm_lst_t functions and sometimes a list can contain another list so i need to know if an item should be deleted with adl_memRelease or wm_lstDestroy if the item is another list…

I would do something like this in the FreeItem callback:

void itemDeleteCallback(void *Item)
{
    if(typeof(wm_lst_t) == Item){
        // Item is another list
        wm_lst_Destroy(Item);
    } else {
        adl_memRelease(Item);
    }
}

But since the typeof operator doesn’t work, how do i accomplish this?


#2

You can’t do that in ‘C’.

What is it, exactly, that you are actually trying to achieve here?


#3

I made a simple key value dictionary api based on the wm_lst functions. Since it’s generic, i can’t know if an item might be another list or just a standard type that can be deleted with adl_memRelease.

As i see it, my only other alternative would be to pass a FreeItem callback with each key that i create :frowning:

Oh and how does va_arg do it then?

Chapter 7.3 Variable-length Argument Lists in
The C Programming Language Second Edition
By Brian W. Kerninghan / Dennis M. Ritchie
ISBN: 0-13-110362-8
Page 156:


#4

AIUI, va_arg is a macro - so it does it at compile time

When citing a reference, you need to give at least title & author; preferably also publisher & ISBN.

Take a look at this: publications.gbdirect.co.uk/c_bo … tdarg.html


#5

Yeah i just found that out from here: cplusplus.com/reference/clib … rg/va_arg/


#6

Exactly - that is why you can get into such a big mess with the likes of printf if the values you pass do not match the specifiers in your format string… 8)