News for hackers. Stuff that matters.
Re:Why I Don't Like Golang (2016) by jolmg on Wednesday June 12, 2019 @08:28PM (#20170774)
> You can pass functions but not return them.

  #include <stdio.h>

  char *f(void) {
    return "Yes, you can...";
  }

  char *(*g(void))(void) {
    return f;
  }

  int main() {
    puts(g()());
    return 0;
  }
Re:Why I Don't Like Golang (2016) by User23 on Wednesday June 12, 2019 @08:58PM (#20170945)
Technically passing and returning function pointers is very different from passing and returning functions. This has implications for things like closures.
Re:Why I Don't Like Golang (2016) by jolmg on Wednesday June 12, 2019 @09:02PM (#20170968)
By the fact that lmm said "You can pass functions", they probably meant "function pointers", since that's the only way you can pass in something that could be referred to as a function in C.

EDIT: At least last I heard. The example I gave is C89, and I know C99 and some GNU extensions. I don't know if a new standard introduced something else that could be referred to as a function that can be passed in but not returned.

A quick google for "c lambda" and "c closure" as well as looking for those keywords in the Wikipedia articles of C11 and C18 turned up nothing, so I guess not.

Re:Why I Don't Like Golang (2016) by earenndil on Wednesday June 12, 2019 @10:19PM (#20171318)
GNU c can have lambda expressions[1]. And clang does even have closures[2].

1: http://walfield.org/blog/2010/08/25/lambdas-in-c.html

2: https://en.wikipedia.org/wiki/Blocks_(C_language_extension)

Re:Why I Don't Like Golang (2016) by saagarjha on Thursday June 13, 2019 @01:17AM (#20172001)
Note that the first example relies on multiple GCC-only features, one of which is the atrocity that is nested functions, and even then technically invokes undefined behavior.
Re:Why I Don't Like Golang (2016) by kazinator on Wednesday June 12, 2019 @11:45PM (#20171644)
GNU C has "downward funarg" closures, like Pascal. They have the same representation as function pointers, which requires the compiled code to generate trampolines (little pieces of machine code that find a PC-relative environment pointer) on the stack. Invoking them requires executable stacks (a linker-level executable option often now turned off by default in major GNU/Linux distros).