ada

Ada: packing record with variable sized array

回眸只為那壹抹淺笑 提交于 2020-01-15 15:59:53
问题 I am looking to create a packed record that can hold an array the varies in length from 5 - 50 elements. Is it possible to do this in such a way that the record can be packed with no wasted space? I will know how many elements will be in the array when I go to create the record. -- the range of the array type Array_Range_T is Integer range 5 .. 50; -- the array type type Array_Type_T is array range (Array_Range_T) of Integer; -- the record type My_Record_T (Array_Length : Integer := 5) is

Ada left hand of assignment must not be limited type

拈花ヽ惹草 提交于 2020-01-15 12:14:26
问题 I am at loss after spending hours on this. Protected type declaration: protected type AdditionMachine is procedure setTask (Item : in WorkerTask); procedure getTask (Item : out WorkerTask); procedure calculate; private machineType : String (1 .. 1) := "A"; job : workerTask; end AdditionMachine; Task: task body SimpleTask1 is Available : Natural := ADDITION_MACHINES; Elements : array (1 .. ADDITION_MACHINES) of AdditionMachine; begin loop select when Available > 0 => accept getMachine (machine

Why isn't my GNAT's standout file descriptor working?

不羁的心 提交于 2020-01-15 09:06:25
问题 As part of a little project, I'm writing a shell in Ada. As such, when I was investigating the system calls, I learned that there are three ways to do it. The POSIX system calls, which are probably the least reliable. Passing the arguments along to C's system(), which I didn't really want to do, since this was about writing the emulator in Ada and not C. Using GNAT's runtime libraries. I chose to go for the last option, considering this to be the most "Ada-like" of the choices. I found a code

String Arrays in Ada

百般思念 提交于 2020-01-14 19:07:29
问题 I have a program in Ada95, in which I have to create an array of strings. This array can contain strings of variable length. Example: I have declared the array in which all the indexes can store strings of size 50. When I assign a smaller string to the above array, I get "Constraint Error". Code: procedure anyname is input_array : array(1..5) of String(1..50); begin input_array(1):="12345"; end anyname; I have tried to create the array of Unbounded_Strings. But that doesn't work either. Can

String Arrays in Ada

人盡茶涼 提交于 2020-01-14 19:07:10
问题 I have a program in Ada95, in which I have to create an array of strings. This array can contain strings of variable length. Example: I have declared the array in which all the indexes can store strings of size 50. When I assign a smaller string to the above array, I get "Constraint Error". Code: procedure anyname is input_array : array(1..5) of String(1..50); begin input_array(1):="12345"; end anyname; I have tried to create the array of Unbounded_Strings. But that doesn't work either. Can

Does Ada have a preprocessor?

假如想象 提交于 2020-01-13 19:08:07
问题 To support multiple platforms in C/C++, one would use the preprocessor to enable conditional compiles. E.g., #ifdef _WIN32 #include <windows.h> #endif How can you do this in Ada? Does Ada have a preprocessor? 回答1: The answer to your question is no, Ada does not have a pre-processor that is built into the language. That means each compiler may or may not have one and there is not "uniform" syntax for pre-processing and things like conditional compilation. This was intentional: it's considered

Does Ada have a preprocessor?

☆樱花仙子☆ 提交于 2020-01-13 19:07:45
问题 To support multiple platforms in C/C++, one would use the preprocessor to enable conditional compiles. E.g., #ifdef _WIN32 #include <windows.h> #endif How can you do this in Ada? Does Ada have a preprocessor? 回答1: The answer to your question is no, Ada does not have a pre-processor that is built into the language. That means each compiler may or may not have one and there is not "uniform" syntax for pre-processing and things like conditional compilation. This was intentional: it's considered

Does Ada have a preprocessor?

℡╲_俬逩灬. 提交于 2020-01-13 19:07:21
问题 To support multiple platforms in C/C++, one would use the preprocessor to enable conditional compiles. E.g., #ifdef _WIN32 #include <windows.h> #endif How can you do this in Ada? Does Ada have a preprocessor? 回答1: The answer to your question is no, Ada does not have a pre-processor that is built into the language. That means each compiler may or may not have one and there is not "uniform" syntax for pre-processing and things like conditional compilation. This was intentional: it's considered

How can you check if an element belongs to one subtype or another?

☆樱花仙子☆ 提交于 2020-01-13 08:21:07
问题 I just learnt about Enums and Types in Ada and decided to write a small program to practice: with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Day is type Day_Of_The_Week is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday); subtype Weekday is Day_Of_The_Week range Monday..Friday; subtype Weekend is Day_Of_The_Week range Saturday..Sunday; function is_Weekday ( dayOfTheWeek: in Day_Of_The_Week) return Boolean is begin if(--?--) end

Quadratic equation in Ada

偶尔善良 提交于 2020-01-09 05:07:52
问题 I just came around and decided to try some Ada. The downside is that the syntax and function strays quite away from C++. So I had to like cram various stuff to get this thing to work. My question is if there are some better way to do this calculation that what I have done here IF(B < 0.0) THEN B := ABS(B); X1 := (B / 2.0) + Sqrt( (B / 2.0) ** 2.0 + ABS(C)); X2 := (B / 2.0) - Sqrt( (B / 2.0) ** 2.0 + ABS(C)); ELSE X1 := -(B / 2.0) + Sqrt( (B / 2.0) ** 2.0 - C); X2 := -(B / 2.0) - Sqrt( (B / 2