gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Assignment to array/record constants.


From: Fischlin Andreas
Subject: Re: Assignment to array/record constants.
Date: Mon, 28 Nov 2022 08:40:32 +0000

Dear Michael,

Yes, agreed. I sought to create some more clarity with perhaps being too restrictive talking only about PIM.

Andreas


ETH Zurich
Prof. em. Dr. Andreas Fischlin
IPCC Vice-Chair WGII
Systems Ecology - Institute of Biogeochemistry and Pollutant Dynamics
CHN E 24
Universitaetstrasse 16
8092 Zurich
SWITZERLAND


+41 44 633-6090 phone
+41 44 633-1136 fax
+41 79 595-4050 mobile

             Make it as simple as possible, but distrust it!
________________________________________________________________________









On 27/11/2022, at 16:34, Michael Riedl <udo-michael.riedl@t-online.de> wrote:

Andreas,

in my view a construct such as

  TYPE   V4 = ARRAY [1..4] OF REAL;

  CONST Fractions = V4{1.0, 1.0/2.0, 1.0/3.0, 1.0/4.0};

or

  CmplxT = RECORD re,im : REAL; END;

  CONST  one   = CmplxT{1.0,0.0};

are legal in ISO Modula-2 (not PIM). But you are absolutely right - an assignment  (e.g. Fractions[0] := 2.0; ) should result in a compiler error.


Michael


Am 25.11.22 um 09:53 schrieb Fischlin Andreas:
Dear Guy,

In Modula-2 the type ARRAY or RECORD is only applicable to variables. Constants declared in the declarative block preceeded by the symbol CONST are only available for the basic types such as INTEGER, CARDINAL, REAL, LONGREAL etc.

Any compiler that would allow to overwrite the value of a constant in an assignment statement would be at fault and such illegal code should be captured always at compile time.

Andreas


ETH Zurich
Prof. em. Dr. Andreas Fischlin
IPCC Vice-Chair WGII
Systems Ecology - Institute of Biogeochemistry and Pollutant Dynamics
CHN E 24
Universitaetstrasse 16
8092 Zurich
SWITZERLAND


+41 44 633-6090 phone
+41 44 633-1136 fax
+41 79 595-4050 mobile

             Make it as simple as possible, but distrust it!
________________________________________________________________________









On 25/11/2022, at 09:31, Guy <guyfieri@getbackinthe.kitchen> wrote:

Hello again Gaius, due to my lack of experience with mailing lists I'm afraid I just recently realized that when attempting to reply to your response to me, I accidentally replied directly to your personal email instead of the mailing list. Due to my email address's domain name, I think that it probably ended up in your junk/spam folder, my mistake.

However since then I have installed Debian and was indeed able to compile the project mostly without issue, so in hindsight it seems that the latest GCC sources just aren't too well suited for macOS (though I'm sure there were quite a few things I was missing on my end).

So today, the issue/question I had is a bit different and instead related to the actual compiler frontend's behavior. One of the first things I happened to try after the successful compilation was some features that I made frequent use of in other languages I have used, that being array/record constants. I saw from a Modula-2 ISO reference that the language also supported this via what it calls "constant constructors". Just to see how the compiler would respond, I tried assigning a value to some test constants I made, but to my surprise it didn't complain and actually replaced its value with the new one from the program body.

More specifically, assignments to the constants in the body of the program via a constant constructor ("constant := TypeName{...}") replaced the current value, but assignments to individual components of the array/record didn't actually have an effect on the values. Running the test program in GDB. I noticed the main procedure of executable programs seemed to be named _M2_<program_name>_init, and was wondering if all array/record constructors (whether for a constant or not), were being moved into some sort of pre-"main" area of code. When stepping through the program, the new/additional assignments to the constant identifiers via constructors don't appear in the places they do in the source.

Please pardon me if this is expected behavior, but I just wanted to ask if this was considered normal.

Thank you, Guy.



Attachment: smime.p7s
Description: S/MIME cryptographic signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]