Initialize WNDCLASS to {0}?

Are there any issues with initializing WNDCLASS to 0 in the following code? The program runs and the window launches. Just not sure if this is bad practice or not.

1
2
3
4
5
6
WNDCLASS wc = {0};

wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpszClassName = "mainWndClass";


My understanding is that by initializing WNDCLASS to '0' it will assign NULL(or '0') to the remaining WNDCLASS parameters. Is this bad practice?
Last edited on
It's generally good practice. But Windows structures often have a size member for version control that must be set, although that's not the case with WNDCLASS. I can't remember what else needs to be set and when.
Fair enough. I suppose until I see performance or memory issues I'll continue to do it this way.
You are very unlikely to see any performance or memory issues - even with default optimization settings the compiler should be smart enough to optimize double assignment.
Excellent responses. Thank you guys for the input. Cheers!
closed account (E0p9LyTq)
I would personally add in one more WNDCLASS struct member initialization:

wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);

otherwise you will have to do all the background painting. Not something I'd do unless I have specific reasons to do so. Better to let Windows do the work. ;)
Topic archived. No new replies allowed.