โŒ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

Is there a way to disable arithmetic operators on a specific type in Ada?

I would like to define HTML response status code numbers as a type but disallow arithmetic operators because it wouldn't make sense for them.

type Status_Code is range 100 .. 599;

function "+" (Left, Right : Status_Code) return Status_Code is
begin
      pragma Assert (1 = -1);
      return Left + Right;
end;

The code snippet above on GNAT will give an error saying assertion will fail on runtime, but that is false when I add two of the numbers together. Is there a way to force a compiler error or at least a warning when arithmetic attempted on a type like this?

GNAT Studio ADA getting error "expected type "Standard.Integer"

In this Intro to Ada Course section about Arrays it shows that I can use a user defined type "Index" to index an array but when I try to index an array using a user defined type it says expected type "Standard.Integer". The reason why I'm asking this is because it explicitly states that you can use any discrete type to index an array.

procedure Cipher is
   type Byte is mod 2**8;
   type BufferArray is array ( 0 .. 15 ) of Byte;
   type Index is range 1 .. 16;
   Buffer: BufferArray := (0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
   buber: Byte := 255;
begin
   --  Insert code here.
   for I in Index loop
      Put( Byte'Image(Buffer(I)) ); --error shows up here
   end loop;
   null;
end Cipher;

Is it just possible that its an issue with this specific version of GNAT?

โŒ
โŒ