The only time where this does not quite work is if the very first field in
the struct/class is not a POD that can be initialized to zero.

A common example would be "struct sigaction" on Linux. The first field is an
anonymous union holding both sa_handler and sa_sigaction. So, this code
wouldn't compile:

  struct sigaction sa = { 0 };

You could write

  struct sigaction sa = { { 0 } };

instead. But this code might not compile on anything other than Linux. As
the union is clearly an implementation-specific detail. A better option
would be to explicitly specify one well-known field:

  struct sigaction sa = { .sa_handler = 0 };

Of course, in this particular case, you would rarely want to completely zero
out the structure anyway. Instead, you would want to set at least some
fields. So, the natural way to write this code would be:

  struct sigaction sa = {
    .sa_handler = MySignalHandler,
    .sa_flags = SA_RESTART
  };

This code is guaranteed to do the right thing, and to zero out all the other
fields in the structure.


Markus

--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: [email protected] 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to