Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"You can still go crazy and jump into the middle of scopes with uninitialized variables."

It is difficult when speaking across languages, but in many cases, no, you can't.

https://go.dev/play/p/v8vljT91Rkr

C isn't a modern language by this standard, and to the extent that C++ maintains compatibility with it (smoothing over a lot of details of what that means), neither is it. Modern languages with goto do not generally let you skip into blocks or jump over initializations (depending on the degree to which it cares about them).

The more modern the language, generally the more thoroughly tamed the goto is.



It doesn't even need to be a modern language to protect against that:

  BEGIN
    INT x := 1;
    print(("x is", x, newline));

    GOTO later;

    INT y := 2;

   later:

    print(("y is", y, newline))
  END
for which we have:

  $ a68g goto.a68 
  x is         +1
  11           print(("y is", y, newline))
                            1           
  a68g: runtime error: 1: attempt to use an uninitialised REF INT value (detected in [] "SIMPLOUT" collateral-clause starting at "(" in this line).
Although admittedly it is a runtime error.

However if y is changed to 'INT y = x + 2;', essentially a "constant", then there is no runtime error:

  $ a68g goto.a68 
  x is         +1
  y is         +0




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: