FAQ Database Discussion Community


How to decode string in specific charset and then encode it in UTF-8?

character-encoding,ada
How, in Ada, do I decode a string coming from the MS Windows terminal, then encode it in UTF-8?

CONSTRAINT_ERROR on reading a file containing “[”

ada,gnat
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...

Understanding bounds of concatenated arrays in Ada 2012

arrays,ada,ada2012
I am reading Programming in Ada 2012 by John Barnes. In section 8.6 he discusses array concatenation and the rules for array bounds, in particular: The lower bound of the result depends on whether the underlying array type is constrained or not. If it is unconstrained...then the lower bound is...

Ada Get_Line not waiting to get Response

ada
I have this strange problem in a program I have been working on. If I attempt to use get_line in Ada to solicit a response from the use after already doing a previous Q&A, the program does not wait for the response. I have put together a little demo program...

What is the 'Address of an Ada subprogram passed as an access parameter?

ada
Compiling the following program without optimization, and then running it, I see Program_Error, raised PROGRAM_ERROR : addreq.adb:16 explicit raise or, updating in view of Simon Wright's answer, raised PROGRAM_ERROR : using address This happens when using GNAT GPL 2014 on either Mac OS X or on GNU/Linux x84_64, on Linux,...

My code raised TASKING_ERROR?

concurrency,task,ada
Assume the following situation: There is a box, which is used to store coins People take money from the box People put money into the box i have take task entry as Add, Subtract, Read and Write. below is my code .now i am confused how to call entry add...

Ada Enums to Values

enums,ada
I can handle this another, not as clean way, but was hoping to be able to take advantage of the following: type Prefix is (Yocto, Zepto, Atto, Femto, Pico, Nano, Micro, Milli, Centi, Deci, None, Deca, Hecto, Kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta); for Prefix use ( Yocto...

What caused this Ada compilation error “ambiguous character literal”?

ada,gnat
I have this Ada code. with Ada.Text_IO; use Ada.Text_IO; procedure for_Loop is begin for Counter in 'A'..'Z' loop Put(Counter); end loop; New_Line; end for_Loop; The Ada compiler (gnatmake) outputs these error message. gcc -c for_loop.adb for_loop.adb:6:24: ambiguous character literal for_loop.adb:6:24: possible interpretation: Character for_loop.adb:6:24: possible interpretation: Wide_Character for_loop.adb:6:24: possible interpretation:...

Access two entries of one task at the same time by different tasks

multithreading,task,ada
I need to acces two different entries of one task by two different tasks. Looks like my knowledge about Ada is not enough to perform this, i also spent a lot of time searching for solution but with no effects. I tried using protected type as a manager but it...

Ada: How to define a random constant?

random,constants,ada
I am currently working through John English' "Ada 95: The Craft of Object-Oriented Programming". I am at task 5.1: Write a program to play a simple guessing game. Define an integer type with a range of values from 1 to 1000 and declare a secret value as a constant of...

Example code detailing difference in typing between Ada and Java [closed]

java,type-conversion,ada
I'm trying to think of a good example detailing the difference between Ada's strict typing and Java's strong typing. Does anyone have a good example for identifying these differences in type conversion using integer based values?

Ada for loop isn't doing correct comparison

loops,for-loop,ada,gnat,ada2012
The simple program is to match the best candidate for a voter with several candidates. There are 10 imaginary topics which the imaginary voter answered; a "-1" means disagreement, a "0" means doesn't care, a "1" means agreement. The candidates also took the same survey on the same topics, and...

Ada non-visible declaration error

ada
I am receiving a "non-visible declaration" error on my Generator. I am converting this code from a single procedure to using multiple procedures and functions. I have truncated the code a bit Any explanation of the non-visible declaration error would be appreciated. The non visible declaration error is occurring in...

Missing “.ali” files when using gnatmake on Mac OS X

osx-yosemite,ada,gnat
What is causing this error? I can't compile Ada .adb files. I have /usr/local/gnat/bin in my path. Output error: gnatmake -d -P/Users/u0/Downloads/test.gpr Adding linker switches for"test.adb". Adding -g TMPDIR = "/private/var/folders/fn/srvkxbdj3bz60q952680ngj40000gn/T" Created configuration file "/private/var/folders/fn/srvkxbdj3bz60q952680ngj40000gn/T/GNAT-TEMP-000001.TMP" "test.ali" being checked ... -> "test.ali" missing. gcc -c -g -gnatf -g -gnat12 -I- -gnatA...

Ada- what do 'at' and 'range' mean/ do?

data-structures,record,ada
I am debugging some software that has been written in two parts- one part in C++, and the other part in Ada- which I have never used before. While reading through some of the Ada code, and looking for variables that contain particlar data, I have found that those variables...

Calling an overridden method from the base class in Ada

oop,polymorphism,ada
I am wondering how to call an overridden method from the parent class in ADA. Let consider the following example. A Parent class has some methods which are overridden by a Child class. There is a method in the Parent class (i.e., Prints) which calls some of its overridden methods....

Ada 2012 and the GNAT GPS IDE Debugger Can't Find Source File

ada,gnat-gps,ada2012
I'm working with a simple hello world single .adb file program in Ada 2012 using the GPS IDE under Windows 7/64. If I keep all the object and source files together everything works. I did have to go to the project properties Switches tab and select the Ada tab and...

Ada 83 Address to Array Conversion

arrays,ada
In the code I inherited, a buffer is passed to a procedure using its start address and length as parameters. This procedure code uses inline assembly language to process the buffer contents. In a new procedure that uses the same parameters, I want to refer to the buffer as an...

How (may?) I export Ada type based on a “new” type from a generic?

generics,declaration,ada
I'm pretty sure this is a trap for new Ada people. I feel there is something simple needed to get this right. I have some older code with the declaration for a Send_Command procedure with a Command_String_Type type parameter based on the Ada.Strings.Bounded generic module. old -- -- -- command.ads...

Ada - Is there a function to make a character or unbounded string to lower case?

ada
Is there a way to accept user input whether it is a character or an unbounded string and convert it to lower case? newLine, N: unbounded_string; M: string(1..26); len: integer; new_line; new_line; put("What is your favorite color?"); new_line; put("Answer:"); get_line(newLine); get_line(M,len); N := to_unbounded_string(to_lower(M)); put_line(N); And for my input: If...

How do you get files with extension from folder in Ada95?

directory,folder,ada
I'm trying to create a function that will look for all .dll files in a specified folder, plugins. All of my web searches (Ada Directories) have work perfectly under Ada 2005, but I need a function that will work for Ada 95. It is to my knowledge that Ada 95...

String manipulation in ada

string,ada
I am getting a path of directory in a string , like "C:\Users\Me\Desktop\Hello”, and I am trying to get the last directory, but without success. I tried a lot of manipulation on the string but in the end of the day i stayed with nothing... i will be grateful to...

How to add different type values to an array in Ada?

ada,ada2012
My goal is to receive from standard input an equation, store that in an array for later use/re-printing, then output a line printing the whole equation AND the answer after just like so: Input: 2+3= Output: 2 + 3 = 5 I am very confused on how to go about...

Maximum size/offset of streamed File using Ada.Streams.Stream_IO.Read

io,filestream,ada,gnat
I try to read specific blocks of Data (around 4096 bytes) from a (possibly) huge file. Using Ada.Streams.Stream_IO.Read() with the GNAT compiler, what would be the maximum offset that I could use? That is, if I wanted to read the last 4 kilobytes of the file, using type Block_Array is...

Unnamed records in Ada

java,ada,anonymous-types,anonymous,ada2012
In Java, you would be able to do something like this: ArrayList.add(new Object(int arg1, int arg2); creating an object without a name and adding it to a list, making it easy to use in a loop. How would I do similar in Ada using records? I have a record: type...

Ada: Fraction part of Float/Fixed as Integer

floating-point,ada
In Ada, I would like to separate out a number like 12.345 out into two distinct integers: whole : integer := 12; fraction : integer := 345; The Whole part is easy, but I don't know how to get the Fraction part. My starting idea is: 12.345 mod Integer(12.345) which...

Ada - Is there a way to traverse through each character of an unbounded string?

ada
I basically have a unbounded string called a for example. And a is currently storing "Hello". I want to check if the letter O is in the string. This is why I want to know if there is a way where I can check each character for a match and...

Assignment to “in” mode parameter not allowed

function,record,ada
It seems that I can't put a record field as a parameter? joueurActuel.c1 := predColonne(joueurActuel.c1); The function: function predColonne (c : T_Colonne) return T_Colonne; where T_Colonne is a subtype of Positive. joueurActuel is an in parameter (joueurActuel : in T_Joueur;) of a function containing the assignment above. T_Joueur is a...

Integer to custom type conversion in Ada

indexing,types,integer,type-conversion,ada
I have an array of some kind of objects, indexed by a type index: type index is new Integer range 1..50; type table is new Array(index) of expression; Now, I need to access one of these expressions, depending on a user entry by keyboard. For that I do following: c:...

Case statement execution steps

ada
I have the following case statement: A = 1 case A is when 1 => A = 2; => Run; when 3 .. 15 => null; when 16 | 17 => Jump; when 2 | 18..35 => Swing; when others => Nothing; end case; So the case statement will go...

Tasks are not run concurrently

concurrency,ada
How can I get these tasks run concurrently, so that the "Hello World from N" messages will be mixed up? My output looks always like this except that 1, 2 or 3 can be interchanged. Hello World from 1! Hello World from 2! Hello World from 3! It does not...

Indexer and reference type for dynamic arrays in Ada

indexing,ada,dynamic-arrays,reference-type
I have the following spec: generic type Value_Type is private; package Containers.Arrays is type Static_Array is array(Positive range <>) of Value_Type; type Static_Array_Access is access all Static_Array; type Dynamic_Array is tagged private; function Length(Self : Dynamic_Array) return Natural with Inline; function "&"(Left : Dynamic_Array; Right : Value_Type) return Dynamic_Array; private...

Compare a string input to an Enumerated type

ada
I am looking to do a comparison of a string to and enumeration. I have written a sample code of what I am attempting. Since a String and and Enumerated type are different, how do I go about doing this properly in Ada? WITH Ada.Text_IO; USE Ada.Text_IO; PROCEDURE ColorTest IS...

How to print Ada.Real_Time.Time variable

time,ada
How to print Ada.Real_Time.Time variable? procedure Main is test : TValue := (value => 0.7, timeStamp => Clock, status => (Valid => False, Unknown => True) ); begin -- print of Test.value Put(Item => Test.value ,Fore => 5, Aft => 3, Exp => 0); -- here I want a print...

Why do all user-defined identifiers start with an uppercase letter?

coding-style,ada
In all Ada source code i know, including the standard library (sorry, i don't know where find it on the web) or the Small game implementation, all non-reserved words starts with uppercase letter. (Last, Stack, Index,…) And because all reserved keywords are highlighted by editor, i guess/hope its not for...

How to stop execution in my program

ada,ada2012
Without copy-pasting my code here, how can I stop my ADA program from executing anymore lines of code during run-time if it calculates a certain value to 'X'? something like: variable_name := variable_name +4; if variable_name >1 then // END program here and dont execute any lines under this one...

Fundamentals of Ada's T'Class

ada
Somewhat embarassed to ask this, but I know it's for the best. I've been programming in Ada for many years now, and understand nearly every part of the language fluently. However, I've never seemed able to wrap my head around T'Class. To borrow from others, can someone "explain it like...

How to initialise an Ada Unbounded String from GetEnv & Literal

string,ada,getenv
G'day, I'm finding compile errors on what ought to be a simple piece of code. the objective is to use an environment variable as part of a default value. We are using Ada95, so I wondered if it's a version thing. The 'model' we stated with looks (something) like this:...