简体   繁体   中英

null check of function pointer doesn't work

I have a code

void(*updateFunc)(EW_Window*) = ((GlfwWindow*)wnd->wndData)->updateCallback;
if (updateFunc)
    updateFunc(wnd);

And if (updateFunc) always passes even updateFunc is 0xcdcdcd (null in debugger). What's going wrong and how I can fix it?

0xcdcdcd is not null-pointer, it is a pattern used to mark unitialized memory. That value is considered as a true value in C. The problem is that ((GlfwWindow*)wnd->wndData)->updateCallback has a wrong value...

Do you mean

void(*updateFunc)(EW_Window*) = ((GlfwWindow*)wnd )->wndData->updateCallback;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM