Article View: comp.arch
Article #54Re: Optimization by programmers
From: David Brown
Date: Mon, 12 Oct 2026 14:20
Date: Mon, 12 Oct 2026 14:20
86 lines
3995 bytes
3995 bytes
On 12/10/2026 13:25, Thomas Koenig wrote: > David Brown <david.brown@hesbynett.no> schrieb: > >> But if you receive a "pointer to const" parameter to a function, you can >> still write via a cast version of the pointer if the original object was >> not defined as "const". (So objects defined as "const" may be placed in >> read-only memory of some kind, and trying to change them might cause a >> crash, signal, bus-error, etc.) > > In FORTRAN, it used to be possible on systems such as /360 to write > > CALL FOO(21) > WRITE (*,*) 21 > END > > SUBROUTINE FOO(N) > N = 42 > END > > and get a printout of 42 (21 is only half the truth, > remember!) because the compiler put the constants in read/write > storage and arguments were passed via address. (We used to call > this "Variation der Konstanten", which translates to "variation > of parameters", from ODE theory. > Yes, that "feature" of old FORTRAN is rather famous. Forth is arguably even better for this : : 21 42 ; 21 . 42 ok That is - you can redefine the word "21" to put the value 42 on the stack. Then if you ask for the number "21", you get the value 42. It is not an oddity of the implementation, but the way the language works. > On modern systems, you get a bus error: > > $ ./a.out > > Program received signal SIGSEGV: Segmentation fault - invalid memory reference. > > Backtrace for this error: > #0 0x72b109a23e59 in ??? > #1 0x72b109a22e75 in ??? > #2 0x72b10964532f in ??? > at ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0 > #3 0x401172 in foo_ > at /tmp/crash.f90:6 > #4 0x40118f in MAIN__ > at /tmp/crash.f90:1 > #5 0x401226 in main > at /tmp/crash.f90:3 > > > But it would be interesting to be able to put arguments into > storage which can be changed by the caller, but not the callee, > sort of a read-only stack, but I am not sure how one would > efficiently implement that. > > (Modern Fortran offers INTENT for that, so > > CALL FOO(21) > WRITE (*,*) 21 > END > > SUBROUTINE FOO(N) > INTEGER, INTENT(IN) :: N > N = 42 > END > > gets you > > error.f90:7:7: > > 7 | N = 42 > | 1~ > Error: Dummy argument 'n' with INTENT(IN) in variable definition context (assignment) at (1) >
Technical Details
Message-ID:
<11aiqc0$3kr94$3@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<1177fdi$26ea4$1@dont-email.me> <11a3ofn$2ak3s$1@dont-email.me> <11a5hd5$4qb$1@reader2.panix.com> <11a5lqo$2v5bq$1@dont-email.me> <11a6870$41j$1@reader2.panix.com> <11a6a6h$37i1n$1@dont-email.me> <1791742457-5857@newsgrouper.org> <11agm4p$2tfut$1@dont-email.me> <11ahs8q$38ir0$4@dont-email.me> <11aig3c$3hdcn$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.arch Subject: Re: Optimization by programmers Date: Mon, 12 Oct 2026 16:20:48 +0200 Organization: A noiseless patient Spider Lines: 86 Message-ID: <11aiqc0$3kr94$3@dont-email.me> References: <1177fdi$26ea4$1@dont-email.me> <11a3ofn$2ak3s$1@dont-email.me> <11a5hd5$4qb$1@reader2.panix.com> <11a5lqo$2v5bq$1@dont-email.me> <11a6870$41j$1@reader2.panix.com> <11a6a6h$37i1n$1@dont-email.me> <1791742457-5857@newsgrouper.org> <11agm4p$2tfut$1@dont-email.me> <11ahs8q$38ir0$4@dont-email.me> <11aig3c$3hdcn$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 12 Oct 2026 14:20:49 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3829028"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182cz51cUxLb+wLI+z/GVZgN4K+djsenJc="; posting-host="711f10de653bed0662d2460037681553" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:w6Zc60vuboxCwxVy9PS2cAHR750= sha256:xE2T+oKBnhxZnW0qtwUbSnAhQpLmAXLe7J+wZt13UQo= sha1:r1EFRvuc2YTpyBfJK5ZUIzNb9iE= sha256:6aQUZUyUNJEuUuXip0VmyIv73g3UyY41DzEH5DnsuXY= In-Reply-To: <11aig3c$3hdcn$1@dont-email.me> Content-Language: en-GB, nb-NO