Tag: api design

是否从size_t或uintptr_t来回转换指针会破坏严格的别名?

我建议更改一个库,其公共API目前看起来像这样: typedef size_t enh; /* handle */ int en_open(enh *handle) { struct internal *e = malloc(…); *handle = (enh)e; return 0; } int en_start(enh handle) { struct internal *e = (struct internal*)handle; return do_something(e); } 这种用法,来回于size_t破坏严格的别名吗? 为了记录,我建议在公共API中使用struct internal的典型opaque前向声明, 如此Programmers.SE关于相同代码的问题所示。