โŒ About FreshRSS

Normal view

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

Penultimate array index retrieval

Suppose the following generic procedure to print the elements of an array indexed by a discreet type (note the slight logic added to prevent the printing of an extra , past the end of the last element):

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Array_Printer is
   
   generic
      type Index is (<>);
      type Int_Array is array (Index range <>) of Integer;
   procedure Print(IA: Int_Array); 
   
   procedure Print(IA: Int_Array) is
      -- Penultimate: Index := Index'Pred(IA'Last); -- raises CONSTRAINT_ERROR for IA'Length = 1
   begin
      Put("[");
      for I in IA'First .. Index'Pred(IA'Last) loop
         Put(IA(I), 0);Put(",");
      end loop;
      Put(IA(IA'Last), 0);
      Put("]");      
   end Print;
   
   type Int_Array is array(Positive range <>) of Integer;
   
   IA: Int_Array := (-3, -2, -1, 0, 1, 2, 3);
   IA2: Int_Array := (1 => 0);
   
   procedure Print_Int_Array is new Print(Index => Positive,
                                          Int_Array => Int_Array);
   
   begin
      Print_Int_Array(IA);   
end Array_Printer;

When this procedure runs with an array of length > 1 (e.g. IA) it correctly prints the array ([-3,-2,-1,0,1,2,3]). However, when it is given an array of length = 1 (e.g. IA2) then, perhaps surprisingly, the penultimate index calculation in the for-loop doesn't raise a CONSTRAINT_ERROR (due to a predecessor not existing) and the expected result ([0]) gets printed.

When that calculation is done elsewhere however (e.g. in the declarative section of the procedure) then that exception is raised, indeed.

Is the compiler smart enough to figure-out there's only one element in the array and hence generates a null range for the for loop?

Gnatstudio seems to be invoking gprbuild with -cargs -g -O0

Any thoughts? - Thanks

Cannot run Gnat Studio

I'm trying to run Gnat Studio on Ubuntu 22.04 but I get the following error:

/opt/gnatstudio/bin/gnatstudio_exe: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

I have installed it via the following steps:

  • Downloaded the "x86 GNU Linux (64 bits)" community edition and ran this
  • Ran /opt/GNAT/2021/doinstall
  • Ran /opt/gnatstudio/bin/gnatstudio and got the above error (sudo-running this yields the same error)

I'm wondering if this is down to 22.04 being a very recent release and some shared libraries are missing from the installation bundle?

Any pointers would be much appreciated.

Thanks

Alire fails with error when building project

I am following the steps here https://pico-doc.synack.me/ to create a simple Ada program to flash a LED on the Raspberry Pi but have come across an issue when building with Alire.

Using the above steps, running either:

alr with pico_bsp

or

alr build

the following error is returned:

error: Could not add community index: Command ["git", "submodule", "update", "--init", "--recursive", "--progress"] exited with code 1

Is there something missing from the above git command that Alire runs? (sudo-running these commands returns the same error)

Searching for this exact error yields zero results.

I am on Ubuntu 16.04 and have the git command that comes with that.

Any ideas/pointers would be greatly appreciated.

Thanks

GNAT GPL Ada fails will linkage error when cross-compiling for the Raspberry pi

I am trying to build a simple "hello_there" Ada app to run on a Raspberry Pi 2/Raspbian machine but have come across a linkage issue.

So far, I've done the following and had the following issues:

  1. Downloaded the "Raspberry Pi 2 Linux" GNAT GPL Ada toolchain for cross compiling (linux-on-linux) on the host machine (Ubuntu 16.04)

  2. Ran "doinstall" on the host machine successfully.

  3. Created a simple "hello_there.adb" file which just prints a message to the console.

  4. Ran {INSTALL_ROOT}/gnat-gpl-2016-raspberrypi-linux-linux-bin/bin/arm-linux-gnueabihf-gnatmake -v hello_there.adb to build this small app.

  5. That complained that the crt1.o | crti.o | crtn.o files cannot be found and since I couldn't use the ones under /usr/lib/x86_64-linux-gnu/ on the host machine (as I assume, these can only be used for a x86 target) the only solution I could find was to copy these files from the target machine which are located under /usr/lib/arm-linux-gnueabihf to the gnatmake command dir. That stopped the linker complaining about these.

  6. Ran again {INSTALL_ROOT}/gnat-gpl-2016-raspberrypi-linux-linux-bin/bin/arm-linux-gnueabihf-gnatmake -v hello_there.adb but now the linker is complaining with the following error:

    {INSTALL_ROOT}/gnat-gpl-2016-raspberrypi-linux-linux-bin/bin/../libexec/gcc/arm-linux-gnueabihf/4.9.4/ld: cannot find -lc

    It looks like compilation and binding complete fine but but linking fails. The full output is the following:

    GNATMAKE GPL 2016 (20160515-49)
    Copyright (C) 1992-2016, Free Software Foundation, Inc.
      "hello_there.ali" being checked ...
      -> "hello_there.ali" missing.
    arm-linux-gnueabihf-gcc -c hello_there.adb
    End of compilation
    arm-linux-gnueabihf-gnatbind -x hello_there.ali
    arm-linux-gnueabihf-gnatlink hello_there.ali
    /home/savvas/opt/GNAT/gnat-gpl-2016-raspberrypi-linux-linux-bin/bin/../libexec/gcc/arm-linux-gnueabihf/4.9.4/ld: cannot find -lc
    collect2: error: ld returned 1 exit status
    arm-linux-gnueabihf-gnatlink: error when calling /home/savvas/opt/GNAT/gnat-gpl-2016-raspberrypi-linux-linux-bin/bin/arm-linux-gnueabihf-gcc
    arm-linux-gnueabihf-gnatmake: *** link failed.
    

Is the linker looking for a clib (or some other filename?) file somewhere in the library path or is there something else going on? I'm new to gcc compilation/linking and am trying to make sense of this.

Any pointers, much appreciated.

Thanks

โŒ
โŒ