News for hackers. Stuff that matters.
Re:Anonymous functions in C by mtdewcmu on Saturday June 21, 2014 @06:38PM (#7926264)
Yeah. C is a boring language that barely ever changes. But I'm not sure there isn't wisdom in being dull.
Re:Anonymous functions in C by nitrogen on Saturday June 21, 2014 @08:06PM (#7926431)
Compound literals in C are awesome like it's 1999:

Assuming you have this:

   struct point {
      float x, y, z;
   };
   void do_something_with_point(struct point *p);
You can do this:

   do_something_with_point(&(struct point){.x = 1.5, .y = 1.5, .z = 3.5});
Re:Anonymous functions in C by mtdewcmu on Saturday June 21, 2014 @08:36PM (#7926485)
You can take the address of a literal?

Being able to specify a literal for a struct is useful. You can, for instance, put the literal in a macro and use the macro to initialize or reset a struct. It's better than having to write additional functions to do something trivial.

Re:Anonymous functions in C by nitrogen on Saturday June 21, 2014 @11:19PM (#7926796)
Yes, you can. You can use it to create an approximation of named parameters, because struct members that don't have an initializer will default to zero. It's still not nearly as compact as, say, Ruby, but for C it's pretty awesome and fast.
Re:Anonymous functions in C by mtdewcmu on Sunday June 22, 2014 @06:46AM (#7927493)
That's interesting. You know you can pass structs by value, too, so I'm not sure how necessary it is to take the address.
Re:Anonymous functions in C by nitrogen on Sunday June 22, 2014 @12:18PM (#7928260)
It can be useful for an API that expects pointers for whatever reason.