From: bedriemir on 23 Apr 2010 05:20 Dear Friends, I will be very happy si quelue'un peut m'éclairer sur.... what is the relation of root_integer , universal_integer and Integer I think people are arguing on the definiton - in fact very scientific - in the LM I am getting different explanations from different sources, what I have understood is root_integer is a special definition type , it is not root of anything , just implemented for the supression of ambiguities which arise with universal_integer, so it should be considered as the base type of universal_integer and his operators has the priority over universal_integer . Similar situations arise in some other types too. universal_integer is the base of all integers. it has examplaires in integer constants but we can't use its instances. The first operative type is Integer . The base type of Integer is universal_integer, the first subtype of Integer is itself, then other subtypes may follow... is it right or am I missing something ? Bedri DoÄan Emir (Chem. & Chem.Eng) (Istanbul University) bedri(a)bedriemir.com
From: J-P. Rosen on 23 Apr 2010 06:01 bedriemir a écrit : > what is the relation of root_integer , universal_integer and Integer > Root_Integer is an (anonymous!) type that includes all values acceptable by the implementation; i.e. its range is System.Min_Int..System.Max_Int. Conceptually, all integer types are derived from Root_Integer; i.e. if you write: type Age is range 0..125; it becomes for the compiler: type Age is new Root_Integer range 0..125; (LRM 3.5.4 (14)) Universal_Integer is more like the set of the mathematical integers; it is the type of integer literals, but any use of one of its values gets immediately converted to the expected type (this a slightly simplified model). (LRM 3.4.1 (6/2) Integer is just a predefined integer type, defined in package standard, with no special property. It is used to index strings, but safe for that, many projects forbid its use because it is not portable. Abuse of type Integer is generally an indication that the programmer has not been educated in defining proper types! A last word: a casual programmer does not need to care about root_integer and universal_integer. Leave that to lawyers! -- --------------------------------------------------------- J-P. Rosen (rosen(a)adalog.fr) Visit Adalog's web site at http://www.adalog.fr
From: Adam Beneschan on 23 Apr 2010 15:12 On Apr 23, 2:20 am, bedriemir <bedrie...(a)gmail.com> wrote: > Dear Friends, > > I will be very happy si quelue'un peut m'éclairer sur.... > > what is the relation of root_integer , universal_integer and Integer > > I think people are arguing on the definiton - in fact very scientific > - > in the LM > > I am getting different explanations from different sources, > > what I have understood is > > root_integer is a special definition type , it is not root of > anything , just implemented for the supression of ambiguities which > arise with universal_integer, so it should be considered as the base > type of universal_integer and his operators has the priority over > universal_integer . Similar situations arise in some other types too. > > universal_integer is the base of all integers. it has examplaires in > integer constants but we can't use its instances. The first operative > type is Integer . The base type of Integer is universal_integer, the > first subtype of Integer is itself, then other subtypes may follow... > > is it right or am I missing something ? You really don't need to know anything about root_integer unless you're a language lawyer. root_integer is defined to help get the overload resolution rules right; without a certain rule in 8.6 that involves root_integer, some expressions that we don't want to be ambiguous would be ambiguous and therefore illegal. So don't worry about it. "universal integer" is the implied type of all integer literals, and the type of named numbers (constants with no type) that have integer values, e.g. A_Thousand : constant := 1000; The main thing to know about universal integers is that they're compatible with any other integer type. So if you declare a procedure with *any* type of integer parameter, you can use an integer literal or a named integer number as the parameter when you call it. Also, if you see an attribute in the manual that is a function that takes a universal integer parameter, the actual parameter can be any integer type (including universal integer). "universal integer" is an implied type only, though; you can't declare a variable or anything else as having that type. Integer is one of the predefined integer types in Standard (and most implementations have Short_Integer and/or Long_Integer too). Those are the types you can use in your program (unless your organization has a policy against the standard integer types, which made sense back in Ada 83 times since there was no guarantee that Integer had to support any integers larger than 0; in Ada 95+ you can safely use Integer without worrying about portability if you will never have a value outside of the range -32767..32767). Hope this helps, -- Adam
From: Robert A Duff on 26 Apr 2010 19:11 bedriemir <bedriemir(a)gmail.com> writes: > what is the relation of root_integer , universal_integer and Integer universal_integer is sort of like root_integer'Class. All integer types you declare are implicitly derived from root_integer. Integer, which is Standard.Integer, is derived from root_integer as usual. "Integer" is badly named (since it's not the true infinite set of integers), and Standard is badly named (since it contains types like Integer with non-standard, implementation-defined ranges). Typically, Integer has a range of -2**31..2**31-1. Most of the time, root_integer and universal_integer expressions have static values (known at compile time), and therefore have infinite range. For example, you can say: N : constant := 2**999; even though your computer doesn't have 999 bits in a machine integer. At run-time, however, root_integer and universal_integer expressions will use the largest integer type supported at run time (64-bits, in GNAT). - Bob
From: AdaMagica on 27 Apr 2010 00:55 For a discussion of universal_integer, root_integer and any integer type derived from the latter, see: http://en.wikibooks.org/wiki/Ada_Programming/Type_System#Elaborated_Discussion_of_Types_for_Signed_Integer_Types (I do hope the wiki is correct on this.)
|
Pages: 1 Prev: Ada.Containers Hash function for a set of small integers Next: Web browser in Ada |