logoalt Hacker News

layer8yesterday at 6:59 PM1 replyview on HN

The casting of the function type assumes that the item pointer type (e.g. Foo*) has the same representation as void*, which the C standard doesn’t guarantee (in standardese: the two types aren’t “compatible”). Calling the function with the converted type therefore constitutes undefined behavior. It also impacts aliasing analysis by compilers (see [0], incidentally), even if the pointer representation happens to be the same.

This casting of the functions to different argument types constitutes the core of the type safety of the generic invocations; I’m not sure it can be fixed.

[0] https://news.ycombinator.com/item?id=44421185


Replies

dhooperyesterday at 7:24 PM

This is addressed in the footnotes. casting is not the core of the type safety. Read the whole article.

show 3 replies