2 ms·
My C++ is rusty (no pun intended), but if your code also has to compile as C++, I think this will work instead of memset: struct addrinfo hints = {0}; If C+
by Someone 8y ago
My C++ is rusty (no pun intended), but if your code also has to compile as C++, I think this will work instead of memset:
struct addrinfo hints = {0};
If C++ requires
struct addrinfo hints = {};
instead, you could create a macro, and write
struct addrinfo hints = ALL_ZEROES;
- loeg 8y agoSure. C++ has initializers ({1,2,3}), it just doesn't have C99 designated initializers ({.a = 1, .b = 2, .c = 3}). This is one of the main pain points around C++ not being a true superset of C.
- hedora 8y agoG++ actually says “sorry” when it bails on that. The other (bigger) pain point is that malloc returns void*, and C++ requires a cast.