โŒ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNewest questions tagged ada - Stack Overflow

Ada types using "(<>)"

I am looking at some legacy Ada code.

type My_Test_Type is (<>);
type My_Table_Type is array(My_Test_Type) of Integer;

When I try to use this code in the GNAT community IDE, I get this error:

ads:9:26: error: identifier expected

This is the line it's pointing to:

type My_Test_Type is (<>);

When I build the code in the legacy IDE, it compiles and runs fine.

Any ideas what is going on here?

I've tried this only on my local PC running GNAT Studio Community 2021 (20210423) hosted on x86_64-w64-mingw32.

The legacy system is a cross compiler for the Power PC. It's old.

Ok, Here is more context.

I took the above lines an created a package which I am building and running in GNAT Studio community addition.

Here is the my_generic.ads

package My_Generic is
 generic
   type My_Test_Type is (<>);
   type My_Table_Type is array(My_Test_Type) of Integer;
   --
   My_Table : My_Table_Type;
   procedure InitMyTable(My_Table : My_Table_Type);   
end My_Generic;

Here is my_generic.adb

with GNAT.IO; use GNAT.IO;
package body My_Generic is
   procedure InitMyTable (My_Table : My_Table_Type) is
   begin
      Put_Line("Entered InitMyTable");
      for i in 1..1000 loop
         My_Table(i) := i + 1000;
      end loop;
      null;
   end InitMyTable;
end My_Generic;

Main is
--...
--...
   InitMyTable_i = new InitMyTable(My_Test_Type => range 1..10);
begin
--...
--...
   Put_Line ("Initializing My table (<>)");
   InitMyTable_i;

end Main;

when I build I get error: declaration expected on the line "InitMyTable_i = new InitMyTable(My_Test_Type => range 1..10);"

I basically have no idea what is going on here. I've tried many different ways to get things to work. Any of the docs I have found, including the ones suggested below, are not helpful.

Thanks

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?

โŒ
โŒ