gm2
[Top][All Lists]
Advanced

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

Re: Assignment to array/record constants.


From: Guy
Subject: Re: Assignment to array/record constants.
Date: Fri, 25 Nov 2022 03:22:22 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0

Thank you for the quick responses Andreas,

I did notice that the original reference from Wirth's PIM4 book included no such mention of records and arrays being supported for constants and assumed it was a feature added by specific compilers (I noticed that Modula-3 supported this same syntax as well, but I'm unsure of it's actual origins).

Without really thinking about whether GNU Modula-2 supported this, I tried it out and the compiler didn't reject it, so I assumed it was possibly supported here too, but that doesn't seem to be the whole case. Though it isn't apart of the PIM/ISO language references and while I have not checked the compiler sources, the feature/syntax seems to be present here in some sort of form it seems? Albeit while exhibiting strange behavior.

I meant to attach this in the original email, but forgot. So this time I have included an example program that depicts the behavior. I compiled it with GM2 pulled from the devel/modula-2 GCC branch as of yesterday.


Thank you, Guy.

P.S. I am in the U.S. and it is quite late for me, so I won't be able to reply until the morning.


On 11/25/22 2:53 AM, Fischlin Andreas wrote:
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: constants.mod
Description: application/xml-dtd


reply via email to

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