snaulX
snaulX

Reputation: 17

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?

Upvotes: 0

Views: 105

Answers (2)

Vlad from Moscow
Vlad from Moscow

Reputation: 310990

Do you mean

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

Upvotes: 0

Jean-Baptiste Yunès
Jean-Baptiste Yunès

Reputation: 36401

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...

Upvotes: 3

Related Questions