News for hackers. Stuff that matters.
Re:Ask HN: How does the return statement of a function work? by version_five on Monday April 10, 2023 @02:34AM (#35509733)
You may be interested to contrast how it works in python with C. If you have something like

  int * bar() {
    int d[2] = {1,2};
    return d;}
When you compile with gcc you get

  foo.c: In function ‘bar’:
  foo.c:4:8: warning: function returns address of local  variable [-Wreturn-local-addr]
This is the behavior it seems like you were expecting, where the array is stored on the stack and so a pointer is invalid once the function ends.

There are no comments on this comment yet.