News for hackers. Stuff that matters.
Re:URLs in C (2011) by chriszhang on Wednesday November 04, 2020 @01:49PM (#24991826)
Can you explain "goto a function name" further?

I wrote this:

  #include <stdio.h>

  void f() {
      printf("f");
  }

  int main() {
      goto f;
      return 0;
  }
It creates error:

  foo.c:8:10: error: use of undeclared label 'f'
      goto f;
           ^
  1 error generated.
How can we goto a function name?
Re:URLs in C (2011) by uryga on Wednesday November 04, 2020 @02:18PM (#24992110)
i think GP means that conceptually, you could imagine goto-ing to a function's code - they do compile to labels after all.

fun note: C-- has something like that! iirc it's like calling a function, but reusing the current stackframe:

  jump f(expr1,. . .,exprn);
> "the `jump` statement performs a control jump but carrying parameters. It has as target [...] a procedure address and can optionally transfer arguments to that procedure."

https://www.microsoft.com/en-us/research/wp-content/uploads/...

Re:URLs in C (2011) by piscisaureus on Wednesday November 04, 2020 @03:17PM (#24992659)
This is the first time I've heard about a language called C--, thank you for that.

The concept is not so unique as you might think tho; the more commonly used term is "tail call".

Re:URLs in C (2011) by uryga on Wednesday November 04, 2020 @07:05PM (#24994388)
i always thought "tail call" means a function call that can be optimized in this way (located in a tail position), not the act of call-by-jumping itself. both uses make sense though

re: C--, i think it's mostly used as a compiler IR. (notably in Haskell's GHC)