🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #52

Re: Optimization by programmers

#52
From: Thomas Koenig
Date: Mon, 12 Oct 2026 11:25
71 lines
3424 bytes
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.

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)

-- 
This USENET posting was made without artificial intelligence,
artificial impertinence, artificial arrogance, artificial stupidity,
artificial flavorings or artificial colorants.
Technical Details
Message-ID: <11aig3c$3hdcn$1@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-mail
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>

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: Thomas Koenig <tkoenig@netcologne.de>
Newsgroups: comp.arch
Subject: Re: Optimization by programmers
Date: Mon, 12 Oct 2026 11:25:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <11aig3c$3hdcn$1@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>
Injection-Date: Mon, 12 Oct 2026 11:25:33 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3716503"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/yC86vboO2uI/XjqceN/3P5jQV8ju8IQ0="; posting-host="b89653fca660d5db2c10ab5187f767fe"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:jn7iKUdCgugGI93kO53696vyqT4= sha256:lAHz5LyZj/EyREygZyyMRrsjsI7R/0FLtMRCpjUGXwM=
	sha1:vDOmDWyzOhIErtqnelVRWXsC4eE= sha256:48HlyUX3/Lul/znjlNR0figSgIMoWeUIZiBQpVlHqeY=