gm2
[Top][All Lists]
Advanced

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

gm2 rejecting a constant statement as variable


From: Alice Osako
Subject: gm2 rejecting a constant statement as variable
Date: Sat, 30 Mar 2024 16:04:34 -0400
User-agent: Mozilla Thunderbird

I am currently intending to work with M2PP (https://github.com/m2sf/m2pp), and for this purpose I have been writing a Makefile to compile all of the components and build the preprocessor. I have run the configuration script (using the settings for ISO, GNU, POSIX, 32/64) and started preparing the make targets for the individual sub-modules.

However, I have come across a surprising problem: several constant initializations are being flagged as involving one or more variables. I have confirmed that the assignments in question are, in fact, constant, but the compiler is saying that they aren't.

For example, the constant declaration:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  BitsInUse =
    ORD(AddressableBits > MaxBits) * MaxBits +
    ORD(AddressableBits <= MaxBits) * AddressableBits;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Gives the following error:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/imp/Hash.mod:34:13: error: In implementation module ‘Hash’: in assignment, cannot assign a variable to a constant ‘BitsInUse’
   34 |   BitsInUse =
      |             ^
src/imp/Hash.mod:34:3: error: designator ‘BitsInUse’ is declared as a CONST
   34 |   BitsInUse =
      |   ^~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have confirmed that both
AddressableBits and MaxBits are constants, and the application of +, *, and ORD() on constants clearly should be recognized as constants as well. Indeed, immediately following this initialization is the constant declaration

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  TTP16  = ORD(AddressableBits>16) * 65535 + 1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compiles without complaint.

(I am assuming that
ORD(FALSE) should return zero, and ORD(TRUE) should return one, which it clearly is the intended use in this code - in effect, a pocket ternary _expression_ that only works with numeric values.)

I noted that the error message does not specify the supposed variable in question, which would make it harder to debug even if there were a variable in the assignment.

Am I missing something? I am not inclined to assume that this is a compiler fault, but if it isn't, I am not certain why it would see a variable in these assignments.

reply via email to

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