ada

Two copies of constant appearing in the compiled Elf

纵然是瞬间 提交于 2019-12-11 15:06:09
问题 We are basically using sparc architecture and our language is Ada we are using gnat compiler to compile our code. We observed something funny. Some of the constant in our code are having two or more copies. file.adb: With FileConsts; USE FileConsts Procedure SomeProcedure is A : LONG_FLOAT; Begin A := cSomeConstant; End SomeProcedure; FileConsts.ads cSomeConstant : CONSTANT LONG_FLOAT := 100.0; In the Map file we have basically .rodata 0x40010000 (0x8)file.o .rodata 0x40010008 pfileconsts_

Ada : Variant size in record type

ⅰ亾dé卋堺 提交于 2019-12-11 13:50:33
问题 I having some trouble with the type Record with Ada. I'm using Sequential_IO to read a binary file. To do that I have to use a type where the size is a multiple of the file's size. In my case I need a structure of 50 bytes so I created a type like this ("Vecteur" is an array of 3 Float) : type Double_Byte is mod 2 ** 16; for Double_Byte'Size use 16; type Triangle is record Normal : Vecteur(1..3); P1 : Vecteur(1..3); P2 : Vecteur(1..3); P3 : Vecteur(1..3); Byte_count1 : Double_Byte; end record

Ada GNAT.Serial_Communications behavior on Linux

若如初见. 提交于 2019-12-11 12:09:54
问题 I have an Ada program that communicates with an Intellibox Basic(a box that allows you to control trains) that is connected via USB. Under Windows, I had to install a specific Serial driver (CP210x USB to UART Bridge VCP). With that driver I can communicate perfectly with the box. That means sending commands to the box. Under Linux I'm communicating via /dev/ttyusb0 and I'm able to get messages from the box, but I can't send commands to the box. Nothing happens. I don't get an error or

CONSTRAINT_ERROR on reading a file containing “[”

为君一笑 提交于 2019-12-11 10:38:22
问题 I am reading a simple text file. Everything works as it should, except when an open bracket ("[") character is encountered. Then I get a CONSTRAINT_ERROR. My function is: ---------------------------------------------- -- GET_FILE_CONTENTS function Get_File_Contents (File_Name : in String) return String_Array is -- Loads the entire file into a dynamically sized -- array of Unbounded_Wide_String. -- The line count is used to dynamically size the array. Line_Count : Natural := 0; File : Ada.Wide

Datatype of variable in ada

我的梦境 提交于 2019-12-11 09:38:04
问题 How can I find the datatype of a variable in Ada? For example, given INT : integer; how can I print "the datatype is integer" for this variable? In Python, type() can be used to find the type. Is there any similar function in Ada to find the datatype of a variable? 回答1: Ada is a strongly typed language, and when you declare a variable you specify its type. So there is no use for a function to return the variable's type, as there would be in languages with untyped variables. The program

Returning a limited type in Ada

馋奶兔 提交于 2019-12-11 08:55:14
问题 I am trying to return a limited type via a constructor function. I understand that because it is a limited type, I cannot copy the type but I am not sure of the best way to do it. I have it working using an extended return statement but I have been told that I should be able to return a limited type without it. thing_protected.ads: package Thing_Protected is type Thing is protected interface; procedure Verb_It (Object : in out Thing; Key : String) is abstract; function Create return Thing

Find Maximum Value in Array in Ada

别来无恙 提交于 2019-12-11 07:58:53
问题 I am doing an Ada program with lots of different functions messing with arrays, i got all my sorting functions going, i am now stuck on retrieving the maximum value in an array using a loop invariant to design the loop for that function. any help? 回答1: How about simply looping over the whole array? something like this: function Get_Maximum (Of : My_Array_Type) return Element_Type is Maximum : Element_Type := Of (Of'First); begin for I in Of'First + 1 .. Of'Last loop if Of (I) > Maximum then

Why is named association required for a one-element record aggregate?

蓝咒 提交于 2019-12-11 07:15:30
问题 When an aggregate contains only one element, as below, positional notation results in a compilation error and we have to use named notation only. Why? type singleton is record v : integer; end record; v1 : singleton := (0); results in the compiler message check.adb:6:23: positional aggregate cannot have one component check.adb:6:23: write instead "V => ..." gnatmake: “check.adb" compilation error whereas this is OK: v2 : singleton := (v => 0); 回答1: Parentheses round an expression are

Ada file operation: instantiation and exception

不羁岁月 提交于 2019-12-11 07:09:02
问题 I'm learning Ada and I need some clarifications on file operations. I have just one type: float and I have to create 2 files that will store float values (with append operation). So I'm instantiating a package for the type float and I then declare 2 file variables X_File and Y_File. Then I put exceptions in case the files don't already exist. WITH Ada.Text_IO; WITH Ada.Sequential_IO; PROCEDURE TestWrite6 IS PACKAGE Seq_Float_IO IS NEW Ada.Sequential_IO (Element_Type => Float); X_File : Seq

Ada record representation

徘徊边缘 提交于 2019-12-11 06:17:37
问题 I have a record type as follows: type Rec_T is record a : Bit_12_T; b : Bit_4_T; end record; where Bit_12_T is mod 2**12 and Bit_4_T is mod 2**4 . To tell the compiler the precise alignment of this record, I use the the for use record statement. However, I want to split the a field bewteen the bytes, so I try to do it as follows: for Rec_T use record a at 0 range 0 .. 7; -- The 1st byte a at 1 range 0 .. 3; -- The 2nd byte b at 1 range 4 .. 7; end record; Clearly, this is not the way to do it