* What is the best way to convert Integer to Short_Short_Integer? @ 2010-06-11 1:17 Adrian Hoe 2010-06-11 2:21 ` Adrian Hoe 2010-06-11 3:14 ` Jeffrey R. Carter 0 siblings, 2 replies; 19+ messages in thread From: Adrian Hoe @ 2010-06-11 1:17 UTC (permalink / raw) Hi, Perhaps I have overlook the repository. What is the best (safest) way to convert an Integer to Short_Short_Integer? 1. Using Ada.Unchecked_Conversion raises warning types of unchecked conversion have different size. 2. Using a custom function such as: function To_Short_Short_Integer ( I : Integer ) return SHort_Short_Integer is function Convert_To_Short_Short_Integer is new Ada.Unchecked_Conversion ( Integer, Short_Short_Integer ) ; begin If I >= Short_Short_Integer'First and I <= Short_Short_Integer'Last then return Convert_To_Short_Short_Integer ( I ); else raise Range_Error; end if; end To_Short_Short_Integer; Again, the Unchecked_Conversion will raise the same warning in (1). Is (2) the best (safest) way to do the conversion? Is there any better method? Thanks. -- Adrian Hoe ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-11 1:17 What is the best way to convert Integer to Short_Short_Integer? Adrian Hoe @ 2010-06-11 2:21 ` Adrian Hoe 2010-06-11 3:14 ` Jeffrey R. Carter 1 sibling, 0 replies; 19+ messages in thread From: Adrian Hoe @ 2010-06-11 2:21 UTC (permalink / raw) On Jun 11, 9:17 am, Adrian Hoe <aby...@gmail.com> wrote: > Hi, > > Perhaps I have overlook the repository. What is the best (safest) way > to convert an Integer to Short_Short_Integer? > > 1. Using Ada.Unchecked_Conversion raises warning types of unchecked > conversion have different size. > > 2. Using a custom function such as: > > function To_Short_Short_Integer ( I : Integer ) return > SHort_Short_Integer > is > function Convert_To_Short_Short_Integer is new > Ada.Unchecked_Conversion ( Integer, Short_Short_Integer ) ; > begin > If I >= Short_Short_Integer'First and I <= Short_Short_Integer'Last > then > return Convert_To_Short_Short_Integer ( I ); > else > raise Range_Error; > end if; > end To_Short_Short_Integer; > > Again, the Unchecked_Conversion will raise the same warning in (1). > > Is (2) the best (safest) way to do the conversion? Is there any better > method? > > Thanks. > -- > Adrian Hoe Sorry, I forgot to convert Short_Short_Integer'First and Short_Short_Integer'Last to Integer. -- Adrian Hoe ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-11 1:17 What is the best way to convert Integer to Short_Short_Integer? Adrian Hoe 2010-06-11 2:21 ` Adrian Hoe @ 2010-06-11 3:14 ` Jeffrey R. Carter 2010-06-11 4:26 ` Adrian Hoe 1 sibling, 1 reply; 19+ messages in thread From: Jeffrey R. Carter @ 2010-06-11 3:14 UTC (permalink / raw) You convert between numeric types by using a type conversion: I : Integer := Integer'Last; S : Short_Short_Integer; -- Not portable ... S := Short_Short_Integer (I); If the value of I is not within the range of Short_Short_Integer, the conversion will raise Constraint_Error. This is basic Ada, and if it's not what you want, then you should use another term than "convert" (and a lengthy explanation of what you're trying to achieve and why is probably in order). -- Jeff Carter "In the frozen land of Nador they were forced to eat Robin's minstrels, and there was much rejoicing." Monty Python & the Holy Grail 70 ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-11 3:14 ` Jeffrey R. Carter @ 2010-06-11 4:26 ` Adrian Hoe 2010-06-11 7:07 ` Jeffrey R. Carter 0 siblings, 1 reply; 19+ messages in thread From: Adrian Hoe @ 2010-06-11 4:26 UTC (permalink / raw) On Jun 11, 11:14 am, "Jeffrey R. Carter" <spam.jrcarter....@spam.acm.org> wrote: > You convert between numeric types by using a type conversion: > > I : Integer := Integer'Last; > S : Short_Short_Integer; -- Not portable > ... > S := Short_Short_Integer (I); > > If the value of I is not within the range of Short_Short_Integer, the conversion > will raise Constraint_Error. > > This is basic Ada, and if it's not what you want, then you should use another > term than "convert" (and a lengthy explanation of what you're trying to achieve > and why is probably in order). > > -- > Jeff Carter > "In the frozen land of Nador they were forced to > eat Robin's minstrels, and there was much rejoicing." > Monty Python & the Holy Grail > 70 Sorry for being vague. I have a number which is in the range of -128..127 and is read as Integer (32-bit). The reason that I want to convert to Short_Short_Integer is to save 24 bits of every such value stored in a record type and to enforce its range on user input. The if..else statement performs range checking during conversion. As long as the range is checked, of course, we can use either method: type conversion as Jeff suggested or use Unchecked_Conversion. Range_Error is a programmer defined exception and could be redundant since Ada has already had Constraint_Error. The main purpose of Range_Error is there to differentiate an exception raised from the code or Constraint_Error from within the Ada runtime range checking mechanism. In the event of Range_Error, we will know a value has fallen out of a defined range and an exception is raised from a procedure or function. Which is the preferred method? Short_Short_Integer (I) or Unchecked_Conversion? And why Jeff said Short_Short_Integer not portable? Is the implementation of Short_Short_Integer machine dependent? If Short_Short_Integer is not portable, what is the best implementation in your opinion? Convert to a smaller integer to save mere 24 bits or keep it as 32-bit Integer and perform range checking? In another similar but different scenario, where a value is in the range 0..15 and is read as 32-bit Integer. Should I convert to Unsigned_4? Where: type Unsigned_4 is mod 2**4; for Unsigned_4'Size use 4; Thanks. -- Adrian Hoe ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-11 4:26 ` Adrian Hoe @ 2010-06-11 7:07 ` Jeffrey R. Carter 2010-06-11 8:59 ` J-P. Rosen ` (2 more replies) 0 siblings, 3 replies; 19+ messages in thread From: Jeffrey R. Carter @ 2010-06-11 7:07 UTC (permalink / raw) Adrian Hoe wrote: > > I have a number which is in the range of -128..127 and is read as > Integer (32-bit). The reason that I want to convert to > Short_Short_Integer is to save 24 bits of every such value stored in a > record type and to enforce its range on user input. The if..else > statement performs range checking during conversion. As long as the > range is checked, of course, we can use either method: type conversion > as Jeff suggested or use Unchecked_Conversion. Which byte of the 32-bit integer will Unchecked_Conversion return? > Which is the preferred method? Short_Short_Integer (I) or > Unchecked_Conversion? A type conversion is preferred. > And why Jeff said Short_Short_Integer not portable? Is the > implementation of Short_Short_Integer machine dependent? If > Short_Short_Integer is not portable, what is the best implementation > in your opinion? Convert to a smaller integer to save mere 24 bits or > keep it as 32-bit Integer and perform range checking? Implementations are not required to define Short_Short_Integer (or any other predefined integer type except Integer), so the program may fail on other compilers. Thus, the use of Short_Short_Integer is not portable. The best implementation may be influenced by many factors, but the best approach is to use types defined based on the problem, not predefined types based on the HW. -- Jeff Carter "In the frozen land of Nador they were forced to eat Robin's minstrels, and there was much rejoicing." Monty Python & the Holy Grail 70 ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-11 7:07 ` Jeffrey R. Carter @ 2010-06-11 8:59 ` J-P. Rosen 2010-06-11 12:28 ` Maciej Sobczak 2010-06-11 12:31 ` Brian Drummond 2 siblings, 0 replies; 19+ messages in thread From: J-P. Rosen @ 2010-06-11 8:59 UTC (permalink / raw) Jeffrey R. Carter a �crit : > Implementations are not required to define Short_Short_Integer (or any > other predefined integer type except Integer), so the program may fail > on other compilers. Thus, the use of Short_Short_Integer is not portable. > But the use of Interfaces.Integer_8 is OK. Guaranteed to be signed integer on 8 bits, or to be undefined if the machine does not support such a type - which is a good thing. If you need 8 bit integers and the machine does not support them, you'd better know ASAP! -- --------------------------------------------------------- J-P. Rosen (rosen@adalog.fr) Visit Adalog's web site at http://www.adalog.fr ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-11 7:07 ` Jeffrey R. Carter 2010-06-11 8:59 ` J-P. Rosen @ 2010-06-11 12:28 ` Maciej Sobczak 2010-06-11 19:05 ` Randy Brukardt 2010-06-13 4:26 ` BrianG 2010-06-11 12:31 ` Brian Drummond 2 siblings, 2 replies; 19+ messages in thread From: Maciej Sobczak @ 2010-06-11 12:28 UTC (permalink / raw) On 11 Cze, 09:07, "Jeffrey R. Carter" <spam.jrcarter....@spam.acm.org> wrote: > Implementations are not required to define Short_Short_Integer (or any other > predefined integer type except Integer), so the program may fail on other > compilers. Thus, the use of Short_Short_Integer is not portable. I have seen this argument raised many times already, but it was never substantiated in terms actual risk estimation. Could you please list the compilers that do not implement this type? Or is there somewhere a public list of such incompatibilities? -- Maciej Sobczak * http://www.inspirel.com YAMI4 - Messaging Solution for Distributed Systems http://www.inspirel.com/yami4 ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-11 12:28 ` Maciej Sobczak @ 2010-06-11 19:05 ` Randy Brukardt 2010-06-13 4:26 ` BrianG 1 sibling, 0 replies; 19+ messages in thread From: Randy Brukardt @ 2010-06-11 19:05 UTC (permalink / raw) "Maciej Sobczak" <see.my.homepage@gmail.com> wrote in message news:3133a7d5-37ec-4db7-94f0-df15b3535af1@k39g2000yqb.googlegroups.com... > On 11 Cze, 09:07, "Jeffrey R. Carter" <spam.jrcarter....@spam.acm.org> > wrote: ... > I have seen this argument raised many times already, but it was never > substantiated in terms actual risk estimation. > Could you please list the compilers that do not implement this type? The only predefined integer types in recent versions of Janus/Ada are Integer and Long_Integer. Janus/Ada also has a type System.Byte for compatibility with our Ada 83 compiler, and of course the various types in package Interface. I've never seen "Short_Short_Integer" in any Ada compiler (not that I've been looking). Of course, you can explicitly define an 8-bit signed integer type, but we don't predefine one (it's not very useful); Integer is 16-bit [for compatibility with our compilers going back to the beginning of time, on the 8080/Z80], and Long_Integer is 32-bit. Randy. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-11 12:28 ` Maciej Sobczak 2010-06-11 19:05 ` Randy Brukardt @ 2010-06-13 4:26 ` BrianG 2010-06-13 18:07 ` Maciej Sobczak 1 sibling, 1 reply; 19+ messages in thread From: BrianG @ 2010-06-13 4:26 UTC (permalink / raw) Maciej Sobczak wrote: > On 11 Cze, 09:07, "Jeffrey R. Carter" <spam.jrcarter....@spam.acm.org> > wrote: > >> Implementations are not required to define Short_Short_Integer (or any other >> predefined integer type except Integer), so the program may fail on other >> compilers. Thus, the use of Short_Short_Integer is not portable. > > I have seen this argument raised many times already, but it was never > substantiated in terms actual risk estimation. What do you mean by a risk estimate, a probability for this particular type? I would doubt anyone would have surveyed all Ada compilers just to generate that number. More generically, I can only duplicate when Jeffrey said: If you use a type provided by your Ada compiler that is not defined in the Ada RM, you cannot presume that that type is provided by a different compiler. (I don't see how this would be different from the same situation in any language. For example, how many C++ compilers don't implement a type named Short_Short_Integer?) > Could you please list the compilers that do not implement this type? All that do not claim to implement it. > > Or is there somewhere a public list of such incompatibilities? What incompatibilities, incompatible with what? Might you mean Ada'95/05 RM 3.5.4(25) "An implementation may provide ..." (the only use of that name I could find in either document)? How can any Ada compiler be incompatible with that? > > -- > Maciej Sobczak * http://www.inspirel.com > > YAMI4 - Messaging Solution for Distributed Systems > http://www.inspirel.com/yami4 --In a world where I feel so small -- I can't stop thinking big... ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-13 4:26 ` BrianG @ 2010-06-13 18:07 ` Maciej Sobczak 2010-06-14 7:28 ` Georg Bauhaus ` (2 more replies) 0 siblings, 3 replies; 19+ messages in thread From: Maciej Sobczak @ 2010-06-13 18:07 UTC (permalink / raw) On 13 Cze, 06:26, BrianG <briang...@gmail.com> wrote: > What do you mean by a risk estimate, a probability for this particular > type? The likelihood of getting into trouble by using this type. (I use the word "likelihood" instead of "probability" as this obviously cannot be expressed with a single number.) > I would doubt anyone would have surveyed all Ada compilers just > to generate that number. Because there are so many Ada compilers? > (I don't see how this would be different from > the same situation in any language. For example, how many C++ compilers > don't implement a type named Short_Short_Integer?) Well, here the situation is a bit easier, as no C++ compiler at all implements a type named Short_Short_Integer. However, you might take this page for comparison: http://wiki.apache.org/stdcxx/C%2B%2B0xCompilerSupport It presents the compatibility chart for new language features - that is, it provides the information on which compiler supports which feature. As you see, making such a list is possible. I hope that this example will explain what kind of information I'm looking for. > > Or is there somewhere a public list of such incompatibilities? > > What incompatibilities, incompatible with what? With Short_Short_Integer, of course. I will take the opportunity to extend my question: is there a "compatibility list" for Ada compilers with regard to all language features that are described as optional? Not just Short_Short_Integer, but also Long_Long_Integer (just joking :-) ), pragmas, annexes, etc.? -- Maciej Sobczak * http://www.inspirel.com YAMI4 - Messaging Solution for Distributed Systems http://www.inspirel.com/yami4 ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-13 18:07 ` Maciej Sobczak @ 2010-06-14 7:28 ` Georg Bauhaus 2010-06-14 16:45 ` Keith Thompson 2010-06-15 2:24 ` BrianG 2 siblings, 0 replies; 19+ messages in thread From: Georg Bauhaus @ 2010-06-14 7:28 UTC (permalink / raw) On 6/13/10 8:07 PM, Maciej Sobczak wrote: >> (I don't see how this would be different from >> the same situation in any language. For example, how many C++ compilers >> don't implement a type named Short_Short_Integer?) > > Well, here the situation is a bit easier, as no C++ compiler at all > implements a type named Short_Short_Integer. > > However, you might take this page for comparison: > > http://wiki.apache.org/stdcxx/C%2B%2B0xCompilerSupport I understand this nice list compares the popular PC/workstation compilers; is there a similar list for C++ compilers that includes typical Ada targets? (Maybe Windriver (EDG I understand, but...), CodeWarrior, Greenhills, ...) >>> Or is there somewhere a public list of such incompatibilities? >> >> What incompatibilities, incompatible with what? > > With Short_Short_Integer, of course. Will there be a loss of magic or purpose if you just declared the type you want, with rep clause maybe? (IOW, can't we assume that compilers will do just as good as they do for predefined types? In fact, some of the Shootout programs got better when switching to programmer defined numeric types.) If I'd need "cross language types" or "database types", then there is likely a common need and hence a community for producing a suitable package; no need to get compiler technology in the way. For example, GNADE uses 64bit types for 64bit database types. GNADE cannot be used if the compiler refuses to accept as is (one Windows compiler doesn't). ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-13 18:07 ` Maciej Sobczak 2010-06-14 7:28 ` Georg Bauhaus @ 2010-06-14 16:45 ` Keith Thompson 2010-06-15 4:54 ` Martin Krischik 2010-06-15 2:24 ` BrianG 2 siblings, 1 reply; 19+ messages in thread From: Keith Thompson @ 2010-06-14 16:45 UTC (permalink / raw) Maciej Sobczak <see.my.homepage@gmail.com> writes: > On 13 Cze, 06:26, BrianG <briang...@gmail.com> wrote: >> What do you mean by a risk estimate, a probability for this particular >> type? > > The likelihood of getting into trouble by using this type. > (I use the word "likelihood" instead of "probability" as this > obviously cannot be expressed with a single number.) You don't need to worry about the "probability" that your code is correct if you just write it to be portable and correct in the first place. Not all Ada compilers implement Short_Short_Integer, but all Ada compilers do implement: type My_Type is range -128 .. 127; [...] > I will take the opportunity to extend my question: is there a > "compatibility list" for Ada compilers with regard to all language > features that are described as optional? Not just Short_Short_Integer, > but also Long_Long_Integer (just joking :-) ), pragmas, annexes, etc.? Why the "just joking :-)" for Long_Long_Integer? It's another optional type, and some Ada compilers do implement it. -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-14 16:45 ` Keith Thompson @ 2010-06-15 4:54 ` Martin Krischik 2010-06-22 21:48 ` Keith Thompson 0 siblings, 1 reply; 19+ messages in thread From: Martin Krischik @ 2010-06-15 4:54 UTC (permalink / raw) Am 14.06.2010, 18:45 Uhr, schrieb Keith Thompson <kst-u@mib.org>: > Not all Ada compilers implement Short_Short_Integer, but all Ada > compilers do implement: > type My_Type is range -128 .. 127; for My_Type'Size use 8; otherwise you type might not be as short as you think it is. Martin -- Martin Krischik mailto://krischik@users.sourceforge.net https://sourceforge.net/users/krischik ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-15 4:54 ` Martin Krischik @ 2010-06-22 21:48 ` Keith Thompson 0 siblings, 0 replies; 19+ messages in thread From: Keith Thompson @ 2010-06-22 21:48 UTC (permalink / raw) "Martin Krischik" <krischik@users.sourceforge.net> writes: > Am 14.06.2010, 18:45 Uhr, schrieb Keith Thompson <kst-u@mib.org>: > >> Not all Ada compilers implement Short_Short_Integer, but all Ada >> compilers do implement: >> type My_Type is range -128 .. 127; > > for My_Type'Size use 8; > > otherwise you type might not be as short as you think it is. That depends on whether you care about the size, or only about the range. It might also be rejected if the implementation doesn't use two's-complement. -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-13 18:07 ` Maciej Sobczak 2010-06-14 7:28 ` Georg Bauhaus 2010-06-14 16:45 ` Keith Thompson @ 2010-06-15 2:24 ` BrianG 2010-06-15 21:21 ` Maciej Sobczak 2 siblings, 1 reply; 19+ messages in thread From: BrianG @ 2010-06-15 2:24 UTC (permalink / raw) Maciej Sobczak wrote: >>> Or is there somewhere a public list of such incompatibilities? >> What incompatibilities, incompatible with what? > > With Short_Short_Integer, of course. > > I will take the opportunity to extend my question: is there a > "compatibility list" for Ada compilers with regard to all language > features that are described as optional? Not just Short_Short_Integer, > but also Long_Long_Integer (just joking :-) ), pragmas, annexes, etc.? > > -- > Maciej Sobczak * http://www.inspirel.com > > YAMI4 - Messaging Solution for Distributed Systems > http://www.inspirel.com/yami4 Let me try to make my point again, since you conveniently cut out my reference to the actual language definition you're discussing. What makes Short_Short_Integer an "optional" part of the language? Just because the RM mentions it as an example of types an implementation "may" provide (as "names of the form")? Should implementations that provide no "nonstandard integer types" also be listed in your "compatibility list", since they are also a "may provide"? How many Ada compilers implement "type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);" listed in 3.5.1(14)? BTW, what you're asking for (see M (13)) is required to be documented for each compiler (e.g. in the GNAT RM 4(13)). My original point is that I've never heard of anyone compiling that for all compilers (whatever "all" means - how could you prove the non-existence of others?). If you could come up with what you would consider a useful definition of "all" compilers, and you had the documentation for each (which I presume might require a license in some cases), this shouldn't be difficult to compile. But what's the point? Standard.Short_Short_Integer gains you nothing you can't get by defining your own. (Which brings up another question: What is your "compatible" definition of Short_Short_Integer? There's nothing in the wording that mandates it be 8 bits.) --Half the world cries -- Half the world laughs --Half the world tries -- To be the other half ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-15 2:24 ` BrianG @ 2010-06-15 21:21 ` Maciej Sobczak 2010-06-15 23:39 ` Georg Bauhaus 2010-06-16 1:27 ` BrianG 0 siblings, 2 replies; 19+ messages in thread From: Maciej Sobczak @ 2010-06-15 21:21 UTC (permalink / raw) On 15 Cze, 04:24, BrianG <briang...@gmail.com> wrote: > Let me try to make my point again, since you conveniently cut out my > reference to the actual language definition you're discussing. I have conveniently cut it out as it was not convincing. Now let's have that spelled out explicitly. > What makes Short_Short_Integer an "optional" part of the language? AARM. > Just > because the RM mentions it as an example of types an implementation > "may" provide Well, that's my understanding of the word "may" -> it's optional. > Should implementations that > provide no "nonstandard integer types" also be listed in your > "compatibility list", since they are also a "may provide"? The implementations can be divided into two groups: those that provide this type and those that don't. Is it that difficult to document? > How many Ada compilers implement "type Day is (Mon, Tue, Wed, Thu, Fri, > Sat, Sun);" listed in 3.5.1(14)? Again not convincing - this point is in the "Examples" part, which explains possible uses of the language and not what is provided by language implementations. > BTW, what you're asking for (see M (13)) is required to be documented > for each compiler Excellent - that just makes it easier to compile a compatibility list. > My original point is > that I've never heard of anyone compiling that for all compilers That's an exact answer to my question. > (whatever "all" means - how could you prove the non-existence of > others?). Excellent point - what about making the list open for additional entries? Like, you know, a wiki page instead of carving something in stone? The C++ community could do that, no? > If you could come up with what you would consider a useful > definition of "all" compilers, Like, you know, this one: http://en.wikibooks.org/wiki/Ada_Programming/Installing Looks like a reasonable list for me. > But what's the point? There is a parallel discussion about making the web content more attractive and friendly for Ada newcomers. Sounds like a valid point to me. > Standard.Short_Short_Integer gains you nothing you can't get by defining > your own. Why not correcting the AARM to express this in the first place? > (Which brings up another question: What is your "compatible" definition > of Short_Short_Integer? There's nothing in the wording that mandates it > be 8 bits.) Excellent - what about providing additional information to the "compatibility list" about what are the actual implementation choices? In short - I think you are getting too hot for no reason. -- Maciej Sobczak * http://www.inspirel.com YAMI4 - Messaging Solution for Distributed Systems http://www.inspirel.com/yami4 ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-15 21:21 ` Maciej Sobczak @ 2010-06-15 23:39 ` Georg Bauhaus 2010-06-16 1:27 ` BrianG 1 sibling, 0 replies; 19+ messages in thread From: Georg Bauhaus @ 2010-06-15 23:39 UTC (permalink / raw) On 6/15/10 11:21 PM, Maciej Sobczak wrote: > In short - I think you are getting too hot for no reason. Might it not be tempting to get a little hot because the Implementation Permission integer types seem to have the same characteristics as the row of C int types? Few programmers can handle these. The CVE around libc/strfmon in May is another fine example of that. But newcomers will start using just familiar types if they are there, don't you think? ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-15 21:21 ` Maciej Sobczak 2010-06-15 23:39 ` Georg Bauhaus @ 2010-06-16 1:27 ` BrianG 1 sibling, 0 replies; 19+ messages in thread From: BrianG @ 2010-06-16 1:27 UTC (permalink / raw) Maciej Sobczak wrote: > On 15 Cze, 04:24, BrianG <briang...@gmail.com> wrote: > >> Let me try to make my point again, since you conveniently cut out my >> reference to the actual language definition you're discussing. > > I have conveniently cut it out as it was not convincing. > Now let's have that spelled out explicitly. Um, ok, but I'm not sure why: "An implementation may provide additional predefined signed integer types, declared in the visible part of Standard, whose first subtypes have names of the form Short_Integer, Long_Integer, Short_Short_Integer, Long_Long_Integer, etc." I take the "of the form" and ", etc." as meaning these are examples of a sequence. Shouldn't we also consider Short_Short_Short_Short_Short_Integer? (I assume this would "normally" equate to 1 bit; what's the required range? - I think it would have to be -1..0 to meet the "standard integer type" rules. :-) (That may not be what you meant. ;-) No offense intended. > >> Should implementations that >> provide no "nonstandard integer types" also be listed in your >> "compatibility list", since they are also a "may provide"? > > The implementations can be divided into two groups: those that provide > this type and those that don't. Is it that difficult to document? > So, this one type is the only "incompatibility" you want in your "list"? That seems of extremely limited use. I could understand compiling all of the Annex M stuff for a set of implementations, or even all of the 'optional' types, but not one piece. > >> My original point is >> that I've never heard of anyone compiling that for all compilers > > That's an exact answer to my question. > As long as you understand that this is but one data point (and a small one at that:-). >> (whatever "all" means - how could you prove the non-existence of >> others?). > > Excellent point - what about making the list open for additional > entries? Like, you know, a wiki page instead of carving something in > stone? > The C++ community could do that, no? They'd do that for Ada? Wow! :-):-) For the Ada community, it just takes one person who cares about the issue and who cares to start the list. (That's not me. I don't use these types and wouldn't use that name in any case. It has no meaning to me.) > > In short - I think you are getting too hot for no reason. I haven't been the slightest bit hot (or even particularly warm) about this topic. (Driving home today, that's different - the heat index was around 115, the car was probably 140+ (F).) My comment was simply questioning your use of the word "incompatibility" in this context. You haven't provided anything that is convincing in that regard. I don't think that it is incompatible to fail to provide something that's not required. We apparently have different definitions of the word. Se la vie. --The whole wide world -- An endless universe --Yet we keep looking through -- The eyeglass in reverse ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: What is the best way to convert Integer to Short_Short_Integer? 2010-06-11 7:07 ` Jeffrey R. Carter 2010-06-11 8:59 ` J-P. Rosen 2010-06-11 12:28 ` Maciej Sobczak @ 2010-06-11 12:31 ` Brian Drummond 2 siblings, 0 replies; 19+ messages in thread From: Brian Drummond @ 2010-06-11 12:31 UTC (permalink / raw) On Fri, 11 Jun 2010 00:07:16 -0700, "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org> wrote: >Adrian Hoe wrote: >> >> I have a number which is in the range of -128..127 and is read as >> Integer (32-bit). >>... we can use either method: type conversion >> as Jeff suggested or use Unchecked_Conversion. > >Which byte of the 32-bit integer will Unchecked_Conversion return? Good question. On which machine? :-) >> Which is the preferred method? Short_Short_Integer (I) or >> Unchecked_Conversion? > >A type conversion is preferred. And it has no downside. If you need to distinguish between errors here and a more general "constraint error", it is easy to wrap the conversion in a function which locally handles "constraint error", and does something appropriate (e.g. saturates, or raises "range error"). - Brian ^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2010-06-22 21:48 UTC | newest] Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-06-11 1:17 What is the best way to convert Integer to Short_Short_Integer? Adrian Hoe 2010-06-11 2:21 ` Adrian Hoe 2010-06-11 3:14 ` Jeffrey R. Carter 2010-06-11 4:26 ` Adrian Hoe 2010-06-11 7:07 ` Jeffrey R. Carter 2010-06-11 8:59 ` J-P. Rosen 2010-06-11 12:28 ` Maciej Sobczak 2010-06-11 19:05 ` Randy Brukardt 2010-06-13 4:26 ` BrianG 2010-06-13 18:07 ` Maciej Sobczak 2010-06-14 7:28 ` Georg Bauhaus 2010-06-14 16:45 ` Keith Thompson 2010-06-15 4:54 ` Martin Krischik 2010-06-22 21:48 ` Keith Thompson 2010-06-15 2:24 ` BrianG 2010-06-15 21:21 ` Maciej Sobczak 2010-06-15 23:39 ` Georg Bauhaus 2010-06-16 1:27 ` BrianG 2010-06-11 12:31 ` Brian Drummond
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox