Hacker News new | past | comments | ask | show | jobs | submit login

Casting between void pointers and function pointers is, strictly speaking, undefined behavior. Though it does tend to work, it's not something to rely on.

(And you don't need casts when converting between void pointers and data pointers)




The dlopen/dlsym API uses void *, there’s really no alternative in C.

It might be undefined in the sense that a language lawyer might care, but for any sane implementation it’s completely valid.


AFAIK it's undefined behaviour in ISO C, but not so in POSIX.


c11 fixed this. C++ allows casting as long as you don’t access the intermediate casted item and cast it back to the type it started as.

In practice though, it works pretty much everywhere in my experience.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: