5 ms·
What happens if you take the address of x in that example, and store it in some data-structure that is on the heap? Would that be a recipe for a "segfault"? Do
by amelius 9y ago
What happens if you take the address of x in that example, and store it in some data-structure that is on the heap?
Would that be a recipe for a "segfault"? Do all these languages allow segfaults to happen?
- augustk 9y agoAt least in Oberon there is no "address of" operator.
- pjmlp 9y agoSure there is. MODULE Crash; IMPORT SYSTEM; VAR source: LONGINT; sourceAddress: INTEGER source2: LONGINT; BEGIN source := 23; sourceAddress := SYSTEM.ADR(source); SYSTEM.GET(sourceAddress, source2); (* .... *) END Crash. The issue is that any module that imports SYSTEM is considered unsafe by the compiler.
- pjmlp 9y agoYes, that can happen. However in some of those languages those type of assignments are only allowed in unsafe code, for example in Modula-3 you can only do that in an unsafe module package and the target variable has to be declared as UNTRACED REF.