Ada Program Works in Linux But Not in Gps Windows 10

Ada program works in Linux but not in GPS Windows 10

Until recently, GNAT didn't check for integer overflow by default. It did check for constraint errors, e.g. assigning 0 to a Positive.

Many of us thought this was a strange choice by the compiler developers, because it led to many questions whose root cause was failure to handle integer overflow. The recent change leads us to suppose that the developers now agree!

Your problem arises because of the statement

for Index in 1..5000000 loop
X := X + Index;
end loop;

which would end up with X ~ 10^13, which doesn’t fit in a 32-bit integer (it would fit in a 64-bit integer, but that would be a Long_Long_Integer on most if not all GNAT platforms).

It’s likely that your Windows compiler is GNAT GPL 2016, which shows the new behaviour, while the Ubuntu compiler is an older FSF GCC.

You can tell your Windows compiler to use the old behaviour using the compiler switch -gnato0.

You can tell your Ubuntu compiler to use the new behaviour using the compiler switch -gnato.

To get an exception message on unhandled exceptions in tasks (which otherwise die silently), you can add

GNAT.Exception_Traces.Trace_On (GNAT.Exception_Traces.Unhandled_Raise);

at the beginning of your main program.

How can I run the program written in Ada?

"ARM ELF" is your problem. If you're trying to run an ARM executable on a Windows x86-64 bit platform, you will not succeed. You need a Windows x86-64 (or Windows x86-32) compiler.

What you downloaded was a "cross-compiler" - runs on one platform (Windows 64), but builds binaries for a different platform (ARM).

On the site you went to, try the "x86 Windows (32-bit)" compiler.

Usage example of pragma Task_Dispatching_Policy(Non_Preemptive_FIFO_Within_Priorities);

I am having difficulty placing the pragma correctly.

Focusing on correct placement, note that a Task_Dispatching_Policy pragma is a configuration pragma that must "appear before the first compilation_unit of a compilation."

at least according to GNAT.

As @egilhh comments, the GNAT User Guide describes how tp accomplish this in 3.4.1. Handling of Configuration Pragmas:

Configuration pragmas may either appear at the start of a compilation unit, or they can appear in a configuration pragma file to apply to all compilations performed in a given compilation environment.

In the case of a single compilation unit, simply place the pragma before the first context clause, as shown here:

pragma Task_Dispatching_Policy(…);
with Ada.Text_IO; use Ada.Text_IO;

To apply the pragma more broadly, add it to gnat.adc as described in §3.4.2. The Configuration Pragmas Files.

Ada GPS IDE can't seem to find GtkAda

There are two things here.

First, "project" is key. Whenever you're building something that depends
on a library like GtkAda, it's much much easier if (a) you use GNAT
Project to manage it, and (b) you use the GPR(s) provided by the library
- always assuming it does, of course.

In the case of GtkAda, that means that your GPR needs to "with" GtkAda;

with "gtkada";
project Tinkering is
...

Second, gnatmake or gprbuild needs to be able to find gtkada.gpr.

The easiest way is to install GtkAda in such a way that gtkada.gpr is in
the default place that gnatmake/gprbuild expect to find GPR files. This
is $prefix/lib/gnat. GtkAda obeys this convention, so you could install
GtkAda under the same root as your compiler. I don't know why that's not recommended anyway.

If you don't want to do that, you can add the correct location to the
environment variable ADA_PROJECT_PATH, for example in your case set it
to C:\GtkAda\lib\gnat.

There is a lot of good stuff in the GtkAda README at libre.adacore.com, and in
the GtkAda User's Guide which I see from the README is also included with the
installed package at (in your case) C:\GtkAda\doc\GtkAda\gtkada_ug.

How to find out if an Ada file was compiled using static or dynamic elaboration

Along with the compiled files (.o) there are ALI files (.ali) which are text files with many details about the compilation that has happened.
The first bunch of information is about compiler switches.



Related Topics



Leave a reply



Submit