top | item 47132833

(no title)

cozzyd | 6 days ago

designated initializers are really great and it's really annoying that C++ has such a crappy version of them. I wish there was a way to tell the compiler that the default value of some fields should not necessarily be 0, though it's ergonomic enough to do that anyway with a macro, since repeated values override.

i.e.

  struct foo { int a; struct { float b; const char * c } d; }; 
  #define DEFAULT_FOO  .a = 1 .d = { .b = 2.0f, .c = "hello" }
 
  ...
  struct foo bar = { DEFAULT_FOO, .a = 2 }

discuss

order

No comments yet.