Initialize WNDCLASS to {0}?

Oct 17, 2015 at 9:26am
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 Oct 17, 2015 at 9:26am
Oct 17, 2015 at 1:09pm
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.
Oct 17, 2015 at 7:55pm
Fair enough. I suppose until I see performance or memory issues I'll continue to do it this way.
Oct 17, 2015 at 7:58pm
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.
Oct 17, 2015 at 8:05pm
Excellent responses. Thank you guys for the input. Cheers!
Oct 17, 2015 at 9:58pm
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.