Hacker News new | past | comments | ask | show | jobs | submit login

"Flat Initializer Lists" is given as an example in K&R C I think, at least the first edition, when writing those extra braces to fill out an initializer must have felt very redundant.

These days many compilers will warn if you do this, however, as it is rare people do this and usually indicates a misunderstanding of the type used.

I think it's quite readable though, so it's a shame it causes warnings. What do you think?

  struct { const char *name; int age; } records[] = {
      "John",   20,
      "Bertha", 40,
      "Andrew", 30,
  };



I find it slightly worse to read. It's C, so my brain is in "newlines don't matter" reading mode, so I see an array of 6 things and then have to mentally split them back up.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: