ada

Aggregate Initialization Safety in C++

断了今生、忘了曾经 提交于 2019-12-08 16:39:27
问题 Suppose I have the following struct: struct sampleData { int x; int y; }; And when used, I want to initialize variables of sampleData type to a known state. sampleData sample = { 1, 2 } Later, I decide that I need additional data stored in my sampleData struct, as follows: struct sampleData { int x; int y; int z; }; It is my understanding that the two field initialization left over from my pre- z data structure is still a valid statement, and will be compiled., populating the missing fields

Ada: reading from a file

荒凉一梦 提交于 2019-12-07 17:00:58
问题 I am trying to read a file with a single column of Long_Float values in Ada as follows: with Ada.Text_IO; use Ada.Text_IO; with Ada.Long_Float_Text_IO; with Ada.Sequential_IO; procedure Test_Read is package Seq_Float_IO is new Ada.Sequential_IO (Element_Type => Long_Float); Input_File : File_Type; value : Long_Float; begin Seq_Float_IO.Open (File => Input_File, Mode => Seq_Float_IO.In_File, Name => "fx.txt"); while not End_OF_File (Input_File) loop Seq_Float_IO.Read (Input_File, value); Ada

How to get a line-numbered stack trace for a memory leak on Mac OS X?

瘦欲@ 提交于 2019-12-07 13:09:58
问题 I've managed to get the Xcode leaks tool to report leaks in my command-line GCC Ada program (by adding delay 11.0; at the end to let leaks make its checks) and then $ export MallocStackLogging=1 $ (./foobar &) && leaks foobar which leads to (excerpted) Process 52027: 18 nodes malloced for 2053 KB Process 52027: 2 leaks for 32 total leaked bytes. Leak: 0x1002000c0 size=16 zone: DefaultMallocZone_0x100175000 string '*' Call stack: [thread 0x7fff70bbcca0]: | start | main | _ada_foobar | __gnat

In/Out vs Out in Ada

余生颓废 提交于 2019-12-07 06:01:02
问题 I have a quick Ada question. If I have a procedure where I may write out to a variable, or I might leave it alone, should it be an Out parameter or an In Out parameter? I guess this boils down to the question: What does the caller see if it calls a procedure with a parameter as Out but the procedure doesn't touch the parameter. Does it see the same value? Undefined behavior? The compiler doesn't complain because it sees an assignment to the Out variable...it just happens to be in a

list of unique random numbers in an Interval in Ada

試著忘記壹切 提交于 2019-12-07 05:44:03
问题 I'm sorry to bother you I know this question have been asked quite a lot but never with Ada... I was wondering if there were in the Ada standard library a way to generate a list of unique random numbers (you never pick twice the same number) in O(n) In a way is there an implementation of the Knuth-Fisher-Yates algorithm in Ada? 回答1: There's a discussion of implementing the Fisher–Yates shuffle here. Basically, you need a different range of Discrete_Random in each iteration, as shown here;

Best practice for implementing in Ada (2005 or 2012) an equivalent of the java finalize block

ⅰ亾dé卋堺 提交于 2019-12-07 03:27:13
问题 Java has the finalize block which allows to execute some statements after a block is left (executed even if an exception is raised). Example: try { ... } catch (Exception e) { ... } finally { ... // any code here } Ada has the controlled objects which allows to implement a Finalize operation but there is no finalize block equivalent as in java. This is useful for logging, closing files, transactions and so on (without having to create a specific tagged type for each possible block). How would

Abstraction over container iterators

点点圈 提交于 2019-12-06 21:51:29
I'm talking about Ada 2012 here. I'll let the code speak first: with Ada.Containers.Hashed_Maps; with Ada.Strings.Unbounded; with Ada.Strings.Unbounded.Hash_Case_Insensitive; with Ada.Strings.Unbounded.Equal_Case_Insensitive; package Environments is type Environment is tagged private; function Variable ( E : in Environment; Name : in Ada.Strings.Unbounded.Unbounded_String ) return Ada.Strings.Unbounded.Unbounded_String with Inline; procedure Set_Variable ( E : in out Environment; Name : in Ada.Strings.Unbounded.Unbounded_String; Value : in Ada.Strings.Unbounded.Unbounded_String ) with Inline;

Why has Ada no garbage collector?

寵の児 提交于 2019-12-06 18:48:25
问题 I know GC wasn't popular in the days when Ada was developed and for the main use case of embedded programming it is still not a good choice. But considering that Ada is a general purpose programming language why wasn't a partial and optional (traces only explicitly tagged memory objects) garbage collector introduced in later revisions of the language and the compiler implementations. I simply can't think of developing a normal desktop application without a garbage collector anymore. 回答1: Ada

How to write gnatcheck rules

本小妞迷上赌 提交于 2019-12-06 09:35:04
Is it possible to write your own gnatcheck rules, and if so, can someone point me to a good reference? I am searching for a particular "style" that is being used, and would love if I could simply write a rule that says if you see said style, it will throw up a warning, or an error, this way we can flag when this isn't following a particular standard. A bit of background may be helpful here. While the style checks hold out a lot of promise for enforcing user style guidelines, that isn't exactly what they are for. The main purpose of those checks is to enforce Ada Core 's (The folks who maintain

Creating Incompatible Number Subtypes

↘锁芯ラ 提交于 2019-12-06 08:21:55
In Ada, it is possible to create incompatible equivalent numeric types: type Integer_1 is range 1 .. 10; type Integer_2 is range 1 .. 10; A : Integer_1 := 8; B : Integer_2 := A; -- illegal! This prevents accidental logical errors such as adding a temperature to a distance. Is it possible to do something similar in Java? E.g. class Temperature extends Double {} class Distance extends Double {} Temperature temp = 20.0; Distance distance = temp; // Illegal! EDIT I've discovered an unrelated question with a related answer . This uses annotations and a special processor on compile to issue warnings