Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

  *(void **)&vkCreateDebugReportCallbackEXT = vkGetInstanceProcAddr( ... );
Is there a cleaner/more idiomatic way to do this?


Is there a cleaner/more idiomatic way to do this?

I'm afraid this is the C idiom for assigning a void pointer to a function pointer:

  *(void **) &fptr = getvoidptr();
Without the silly cast you'd get the following warning when compiling with -Wpedantic:

  warning: ISO C forbids assignment between function pointer and 'void *'
Once you learn the idiom, and the reason behind it, it makes things (slightly) easier to parse than dealing with a bunch of typedefs, IMHO.


PFN_vkCreateDebugReportCallbackEXT dbgCreateDebugReportCallback = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT");




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: