I have checked the above program on several on-line compilers, all of them behave according to interpretation 2 above.
Richard claims to get behavior 1 on his compiler.
What is your take on this? Any language lawyers?
On 2023-09-23 22:22, Maciej Sobczak wrote:
I have checked the above program on several on-line compilers, all of
them behave according to interpretation 2 above.
Richard claims to get behavior 1 on his compiler.
What is your take on this? Any language lawyers?
The important thing is the definition of Ada.Text_IO.Integer_IO.Get [ARM A.10.8(7-10)]:
"... skips any leading blanks, line terminators, or page terminators, then reads a plus sign if present or (for a signed type only) a minus sign if present, then reads the longest possible sequence of characters matching
the syntax of a numeric literal without a point. ...
"Returns, in the parameter Item, the value of type Num that corresponds to the sequence input.
"The exception Data_Error is propagated if the sequence of characters read does not form a legal integer literal or if the value obtained is not of
the subtype Num."
So a call to Get can only return a valid value of type Num (Integer for
your case) or raise Data_Error.
If Get is reading "500" then that certainly represents a valid value of
type Integer, and Get should copy that back to the actual parameter.
If you are using Ada (a language with run-time checks), then a check
should be made that the value is in the range of the actual parameter's subtype, here Integer range 0 .. 200. That should fail and
Constraint_Error should be raised.
However, if you are not using Ada because that check has been suppressed, then the actual parameter will be left with the invalid value 500 and Constraint_Error will not be raised.
If I build your program with checks enabled, I get Constraint_Error. If I build it with checks suppressed, I get the not-valid message (GNAT 12.3).
--
Jeff Carter
"If you don't get the President of the United States on that
phone, ... you're going to have to answer to the Coca-Cola
Company."
Dr. Strangelove
32
... for Janus/Ada, enumeration types with specified representations
operate internally on the position numbers
On 2023-09-26 9:13, Randy Brukardt wrote:
... for Janus/Ada, enumeration types with specified representations
operate internally on the position numbers
Hm, that's interesting. Is that also the representation for record
components of such an enumerated type?
For example, if I have:
type Command is (Off, On) with Size => 4;
for Command use (Off => 2, On => 5);
type Two_Commands is record
C1, C2: Command;
end record
with Pack, Size => 8;
TwoC : Two_Commands := (C1 => On, C2 => Off);
will the record components (in memory) have the values C1 = 1 and C2 = 0 (position numbers) or C1 = 5, C2 = 2 (specified representation)?
If they are represented by position numbers in the record, many if not
most of my embedded Ada programs would fail if compiled with Janus/Ada, because the record values stored in I/O control registers or accessed via
DMA would be wrong.
Damn, I thought those programs were not so compiler-dependent :-(
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 335 |
Nodes: | 16 (2 / 14) |
Uptime: | 147:09:04 |
Calls: | 7,411 |
Calls today: | 1 |
Files: | 12,670 |
Messages: | 5,612,993 |