comp.lang.ada
 help / color / mirror / Atom feed
* Re: Type casting question
  1999-12-20  0:00 Type casting question Raju Vemulamanda
@ 1999-12-20  0:00 ` DuckE
  1999-12-21  0:00 ` Robert Dewar
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: DuckE @ 1999-12-20  0:00 UTC (permalink / raw)



Raju Vemulamanda <raju@tridsys.com> wrote in message
news:385E87D8.2B44B800@tridsys.com...
> Question: Could someone please provide some solution
>   to the below?
>
> I have this question in the conversion of values
> between the string and the my own type shown below.
>
> type Bit_5 is range 2#0# .. 2#11111#;
>     for Bit_5'Size use 5;
> subtype Size_Type is Bit_5;
>
> The above is how Size_Type has been declared.
>
> val1 : Jvmfr3_Field_Types.Size_Type := 10;
>
> Suppose I have a string xxx which has the some value in it,
> How can I convert that xxx into the above declared val1?
> I have to copy xxx into val1. I need to somehow do the
> type casting for the above.

Here's a complete example:

with Ada.Text_Io;
procedure Size_Demo is

  package Text_Io renames Ada.Text_Io;

  type Bit_5 is range 2#0# .. 2#11111#;
  for Bit_5'Size use 5;
  subtype Size_Type is Bit_5;

  val1 : Size_Type;
  input_string : String(1..10);
  last_char : Natural;

begin
   Text_Io.Put( "Enter Value => " );
   Text_Io.Get_Line( input_string, last_char );
   val1 := Size_Type'Value( input_string( 1 .. last_char ) );

   Text_Io.Put_Line( "Value is: " & Size_Type'Image( val1 ) );
end Size_Demo;







^ permalink raw reply	[flat|nested] 16+ messages in thread

* Type casting question
@ 1999-12-20  0:00 Raju Vemulamanda
  1999-12-20  0:00 ` DuckE
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Raju Vemulamanda @ 1999-12-20  0:00 UTC (permalink / raw)
  To: comp.lang.ada

Question: Could someone please provide some solution
  to the below?

I have this question in the conversion of values
between the string and the my own type shown below.

type Bit_5 is range 2#0# .. 2#11111#;
    for Bit_5'Size use 5;
subtype Size_Type is Bit_5;

The above is how Size_Type has been declared.

val1 : Jvmfr3_Field_Types.Size_Type := 10;

Suppose I have a string xxx which has the some value in it,
How can I convert that xxx into the above declared val1?
I have to copy xxx into val1. I need to somehow do the
type casting for the above.









^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-20  0:00 Type casting question Raju Vemulamanda
  1999-12-20  0:00 ` DuckE
@ 1999-12-21  0:00 ` Robert Dewar
  1999-12-21  0:00 ` Robert Dewar
  1999-12-21  0:00 ` David C. Hoos, Sr.
  3 siblings, 0 replies; 16+ messages in thread
From: Robert Dewar @ 1999-12-21  0:00 UTC (permalink / raw)


In article <385E87D8.2B44B800@tridsys.com>,
  comp.lang.ada@ada.eu.org wrote:
> Suppose I have a string xxx which has the some value in it,
> How can I convert that xxx into the above declared val1?
> I have to copy xxx into val1. I need to somehow do the
> type casting for the above.


Don't use the term type casting, it is never appropriate in
Ada, and in fact what you want has nothing to do with type
casting in say the C sense.

What you want is conversion routines, provided in Ada using
the 'Value and 'Image attributes, look them up in any Ada book!


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-20  0:00 Type casting question Raju Vemulamanda
  1999-12-20  0:00 ` DuckE
  1999-12-21  0:00 ` Robert Dewar
@ 1999-12-21  0:00 ` Robert Dewar
  1999-12-21  0:00   ` reason67
  1999-12-21  0:00 ` David C. Hoos, Sr.
  3 siblings, 1 reply; 16+ messages in thread
From: Robert Dewar @ 1999-12-21  0:00 UTC (permalink / raw)


In article <385E87D8.2B44B800@tridsys.com>,
  comp.lang.ada@ada.eu.org wrote:
> Question: Could someone please provide some solution
>   to the below?
>
> I have this question in the conversion of values
> between the string and the my own type shown below.
>
> type Bit_5 is range 2#0# .. 2#11111#;
>     for Bit_5'Size use 5;
> subtype Size_Type is Bit_5;


By the way, it is almost certainly wrong to have the base
type of Bit_5 be signed.

Almost certainly what you want here is

  type Bit_5 is mod 2 ** 5;

The size clause is unnecessary in either case, since the
default size in both cases is obviously 5!


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-21  0:00 ` Robert Dewar
@ 1999-12-21  0:00   ` reason67
  1999-12-21  0:00     ` Robert Dewar
  0 siblings, 1 reply; 16+ messages in thread
From: reason67 @ 1999-12-21  0:00 UTC (permalink / raw)


In article <83o9d0$ul9$1@nnrp1.deja.com>,
  Robert Dewar <robert_dewar@my-deja.com> wrote:
> In article <385E87D8.2B44B800@tridsys.com>,

> > type Bit_5 is range 2#0# .. 2#11111#;
> >     for Bit_5'Size use 5;
> > subtype Size_Type is Bit_5;
>
> By the way, it is almost certainly wrong to have the base
> type of Bit_5 be signed.
>
> Almost certainly what you want here is
>
>   type Bit_5 is mod 2 ** 5;

Assuming he is using Ada95 and not Ada 83.

> The size clause is unnecessary in either case, since the
> default size in both cases is obviously 5!

I have used compilers that, unless you specified, put all integer types
to a size of 32 by default. I do not know if the Ada95 LRM specifies
that the type must be sized to the minimum or not.
---
Jeffrey S. Blatt


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-21  0:00   ` reason67
@ 1999-12-21  0:00     ` Robert Dewar
  1999-12-21  0:00       ` reason67
  0 siblings, 1 reply; 16+ messages in thread
From: Robert Dewar @ 1999-12-21  0:00 UTC (permalink / raw)


In article <83of3h$352$1@nnrp1.deja.com>,
  reason67@my-deja.com wrote:
> Assuming he is using Ada95 and not Ada 83.

By convention on this newsgroup, we assume Ada means Ada, i.e.
Ada 95. If people are stuck using an obsolete version of the
language, they need to say so.

> I do not know if the Ada95 LRM specifies
> that the type must be sized to the minimum or not.

Well I do know, or I would not have said what I said :-)

In Ada 95, the size of both types is required to be 5.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-21  0:00     ` Robert Dewar
@ 1999-12-21  0:00       ` reason67
  1999-12-22  0:00         ` Ted Dennison
  1999-12-23  0:00         ` Robert Dewar
  0 siblings, 2 replies; 16+ messages in thread
From: reason67 @ 1999-12-21  0:00 UTC (permalink / raw)


In article <83ookh$aek$1@nnrp1.deja.com>,
  Robert Dewar <robert_dewar@my-deja.com> wrote:

> By convention on this newsgroup, we assume Ada means Ada, i.e.
> Ada 95. If people are stuck using an obsolete version of the
> language, they need to say so.

I think it is risky to assume that new people know the conventions here.
Personally, I have been reading and posting here for a couple months and
I did not know that there was such a convention until you were kind
enough to point it out to me.

I think it is far safer to determine which version of the language they
are using from context. When people use Ada 83 syntax, I assume they are
using Ada 83 unless they state otherwise.
---
Jeffrey S. Blatt


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-20  0:00 Type casting question Raju Vemulamanda
                   ` (2 preceding siblings ...)
  1999-12-21  0:00 ` Robert Dewar
@ 1999-12-21  0:00 ` David C. Hoos, Sr.
  3 siblings, 0 replies; 16+ messages in thread
From: David C. Hoos, Sr. @ 1999-12-21  0:00 UTC (permalink / raw)



Raju Vemulamanda <raju@tridsys.com> wrote in message
news:385E87D8.2B44B800@tridsys.com...
> Question: Could someone please provide some solution
>   to the below?
>
> I have this question in the conversion of values
> between the string and the my own type shown below.
>
> type Bit_5 is range 2#0# .. 2#11111#;
>     for Bit_5'Size use 5;
> subtype Size_Type is Bit_5;
>
> The above is how Size_Type has been declared.
>
> val1 : Jvmfr3_Field_Types.Size_Type := 10;
>
> Suppose I have a string xxx which has the some value in it,
> How can I convert that xxx into the above declared val1?
> I have to copy xxx into val1. I need to somehow do the
> type casting for the above.
Any valid string representation of a scalar value can be converted
to the corresponding value by using the 'Value attribute of the
type.  So.... for your type Bit_5, if you have the declaration:

A_Bit_5_Value : Bit_5;


Then you can say A_Bit_5_Value := Bit_5'Value ("2#10101#");








^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-21  0:00       ` reason67
@ 1999-12-22  0:00         ` Ted Dennison
  1999-12-23  0:00         ` Robert Dewar
  1 sibling, 0 replies; 16+ messages in thread
From: Ted Dennison @ 1999-12-22  0:00 UTC (permalink / raw)


In article <83p0mc$g7g$1@nnrp1.deja.com>,
  reason67@my-deja.com wrote:
> In article <83ookh$aek$1@nnrp1.deja.com>,
>   Robert Dewar <robert_dewar@my-deja.com> wrote:
>
> > By convention on this newsgroup, we assume Ada means Ada, i.e.
> > Ada 95. If people are stuck using an obsolete version of the

> I think it is risky to assume that new people know the conventions
> here. Personally, I have been reading and posting here for a couple
> months and I did not know that there was such a convention until you
> were kind enough to point it out to me.

Ahh. So what you are saying is that this needs to be in the FAQ which we
are currently putting together. Thanks for pointing that out.

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-23  0:00           ` reason67
                               ` (2 preceding siblings ...)
  1999-12-23  0:00             ` Robert Dewar
@ 1999-12-23  0:00             ` Larry Kilgallen
  1999-12-24  0:00               ` Robert Dewar
  3 siblings, 1 reply; 16+ messages in thread
From: Larry Kilgallen @ 1999-12-23  0:00 UTC (permalink / raw)


In article <83tdjp$hts$1@nnrp1.deja.com>, reason67@my-deja.com writes:

>> The notion that Ada means Ada 95 is not an invention of the
>> list, it is the formal position of ISO. Once a new standard
>> comes out, the name refers ONLY to the current standard!
> 
> While, technically, that may be true, in the market place job are
> advertised in the USA as Ada or Ada 95. If a recruiter tells me about an
> Ada job, it has always been (in my experience) an Ada 83 job. If the job
> is Ada 95, then that is specifically stated. People I have worked with
> in the Ada 83 world refer to Ada 83 as simply "Ada". People I have
> worked with in the Ada 95 world refer to the two languages as Ada 83 and
> Ada 95.
> 
> Perhaps your experience is different, but I do not consider ISO's
> position on what can and can not be called Ada to be nearly as relevent
> as what people are actually doing.

Several of the people in the newsgroup have spent many years working on
the development of the Ada 95 standard and then on developing compilers
to implement it (for various vendors).  From their perspective Ada 83
is old, even though for many of us Ada 83 suffices.

You will notice a difference, however, in the degree to which the Ada 95
experts are able to relate to those who are not in their position. Some
of them are much more easygoing, for example Tucker Taft.

Larry Kilgallen




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-21  0:00       ` reason67
  1999-12-22  0:00         ` Ted Dennison
@ 1999-12-23  0:00         ` Robert Dewar
  1999-12-23  0:00           ` reason67
  1 sibling, 1 reply; 16+ messages in thread
From: Robert Dewar @ 1999-12-23  0:00 UTC (permalink / raw)


In article <83p0mc$g7g$1@nnrp1.deja.com>,
  reason67@my-deja.com wrote:
> I think it is far safer to determine which version of the
language they
> are using from context. When people use Ada 83 syntax, I
assume they are
> using Ada 83 unless they state otherwise.
> ---
> Jeffrey S. Blatt


That's a bit bizarre, there is no such thing as using Ada 83
syntax in this context, since all Ada 83 syntax is included
in Ada 95. I really have NO idea what you are talking about!

The notion that Ada means Ada 95 is not an invention of the
list, it is the formal position of ISO. Once a new standard
comes out, the name refers ONLY to the current standard!


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-23  0:00         ` Robert Dewar
@ 1999-12-23  0:00           ` reason67
  1999-12-23  0:00             ` Robert Dewar
                               ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: reason67 @ 1999-12-23  0:00 UTC (permalink / raw)


Before I begin I would like to say that your posts always come across a
little smug to me. If it is important to you that people think you are
smarter than me, I will state for the record that Robert Dewar is
smarter than Jeffrey Blatt. Now with that conclusion already in place,
perhaps the attitude will no longer be required and we can discuss
issues in the future without it.

> > I think it is far safer to determine which version of the
> language they
> > are using from context. When people use Ada 83 syntax, I
> assume they are
> > using Ada 83 unless they state otherwise.
>
> That's a bit bizarre, there is no such thing as using Ada 83
> syntax in this context, since all Ada 83 syntax is included
> in Ada 95. I really have NO idea what you are talking about!

Here is what I am talking about. The original example had the code
fragment:

type Bit_5 is range 2#0# .. 2#11111#;
     for Bit_5'Size use 5;

1. While this is valid in Ada 95, as you pointed out, it is really not
the best way to do it. No Ada 95 programmer would consider that as a
real solution for modeling 5 bits because mod types give you much more.
However, it was the only way to do it in Ada 83.

2. I recently changed jobs in October (I am an Ada Contract Engineer,
I do that often and have a pretty diverse experience in the US Ada
Marketplace) and in the US, the majority of the Ada jobs that were
advertised or that recruiters talked to me about were still using Ada
83.

Given these 2 points, in my experience and the context of the question
asked, I assumed it was Ada 83 and gave/would have given an Ada 83
solution.

Do you understand what I am talking about now?

> The notion that Ada means Ada 95 is not an invention of the
> list, it is the formal position of ISO. Once a new standard
> comes out, the name refers ONLY to the current standard!

While, technically, that may be true, in the market place job are
advertised in the USA as Ada or Ada 95. If a recruiter tells me about an
Ada job, it has always been (in my experience) an Ada 83 job. If the job
is Ada 95, then that is specifically stated. People I have worked with
in the Ada 83 world refer to Ada 83 as simply "Ada". People I have
worked with in the Ada 95 world refer to the two languages as Ada 83 and
Ada 95.

Perhaps your experience is different, but I do not consider ISO's
position on what can and can not be called Ada to be nearly as relevent
as what people are actually doing.
---
Jeffrey Blatt


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-23  0:00           ` reason67
  1999-12-23  0:00             ` Robert Dewar
@ 1999-12-23  0:00             ` reason67
  1999-12-23  0:00             ` Robert Dewar
  1999-12-23  0:00             ` Larry Kilgallen
  3 siblings, 0 replies; 16+ messages in thread
From: reason67 @ 1999-12-23  0:00 UTC (permalink / raw)


In article <83tdjp$hts$1@nnrp1.deja.com>,
  reason67@my-deja.com wrote:
> Before I begin I would like to say that your posts always come across
a
> little smug to me. If it is important to you that people think you are
> smarter than me, I will state for the record that Robert Dewar is
> smarter than Jeffrey Blatt. Now with that conclusion already in place,
> perhaps the attitude will no longer be required and we can discuss
> issues in the future without it.

This paragraph it written badly, my apologies. My meaning is not clear
at all. It sounds like I think you are attacking me personally or have a
vendetta against me. I seriously doubt you know who I am from one day to
the next, so that is not my point. I think you have this attitude with
everyone and I was more than happy to say that I was you inferior if it
will eliminate it when you respond to me (as you would not have to
prove it in your post).
---
Jeffrey Blatt


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-23  0:00           ` reason67
@ 1999-12-23  0:00             ` Robert Dewar
  1999-12-23  0:00             ` reason67
                               ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: Robert Dewar @ 1999-12-23  0:00 UTC (permalink / raw)


In article <83tdjp$hts$1@nnrp1.deja.com>,
  reason67@my-deja.com wrote:
> 1. While this is valid in Ada 95, as you pointed out, it is
really not
> the best way to do it. No Ada 95 programmer would consider
that as a
> real solution for modeling 5 bits because mod types give you
much more.
> However, it was the only way to do it in Ada 83.

Actually it is not at ALL true that "no Ada 95 programmer would
consider that as a real solution", because in practice there
are many people using Ada 95 who have not yet learned all the
new Ada 95 stuff. Yes, there are some people still stuck using
Ada 83, but they will usually identify that in their posts, and
they most certainly SHOULD identify that, because as I said
earlier, Ada means Ada 95, and that is the assumption we
generally make in this newsgroup!

> 2. I recently changed jobs in October (I am an Ada Contract
Engineer,
> I do that often and have a pretty diverse experience in the US
Ada
> Marketplace) and in the US, the majority of the Ada jobs that
were
> advertised or that recruiters talked to me about were still
using Ada
> 83.

There are plenty of people using Ada 95 these days! Indeed many
of the old Ada 83 compilers are no longer supported.

> Given these 2 points, in my experience and the context of the
question
> asked, I assumed it was Ada 83 and gave/would have given an
Ada 83
> solution.
>
> Do you understand what I am talking about now?

Yes, but it's usually a bad idea to assume Ada 83 in any
situation like this.


> > The notion that Ada means Ada 95 is not an invention of the
> > list, it is the formal position of ISO. Once a new standard
> > comes out, the name refers ONLY to the current standard!
>
> While, technically, that may be true, in the market place job
are
> advertised in the USA as Ada or Ada 95. If a recruiter tells
me about an
> Ada job, it has always been (in my experience) an Ada 83 job.
If the job
> is Ada 95, then that is specifically stated. People I have
worked with
> in the Ada 83 world refer to Ada 83 as simply "Ada". People I
have
> worked with in the Ada 95 world refer to the two languages as
Ada 83 and
> Ada 95.

THings are changing rapidly, the kind of environment you talk
about (where Ada still means only Ada 83) is definitely getting
to be the minority case. I have no idea why the jobs
opportunities you are interacting with are primarily Ada 83,
there are lots of openings for good Ada 95 programmers!

> Perhaps your experience is different, but I do not connsider
ISO's
> position on what can and can not be called Ada to be nearly as
relevent
> as what people are actually doing.


Well we definitely need to educate here, and the FAQ that
is being prepared now will clarify the convention that on this
newsgroup Ada means Ada as defined by the current ISO/ANSI
standard, and if you want to talk about Ada 83, you need to
say so!


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-23  0:00           ` reason67
  1999-12-23  0:00             ` Robert Dewar
  1999-12-23  0:00             ` reason67
@ 1999-12-23  0:00             ` Robert Dewar
  1999-12-23  0:00             ` Larry Kilgallen
  3 siblings, 0 replies; 16+ messages in thread
From: Robert Dewar @ 1999-12-23  0:00 UTC (permalink / raw)


In article <83tdjp$hts$1@nnrp1.deja.com>,
  reason67@my-deja.com wrote:
> I will state for the record that Robert Dewar is
> smarter than Jeffrey Blatt.

This has nothing to do with who is smater than whom! It simply
is a convention we have followed in this newsgroup that we take
Ada to mean Ada as defined by the ISO/ANSI standard, and that
Ada 83, an obsolete language, needs to be labeled as such.

Part of the reason we take this veiwpoint is that to some extent
this is an advocacy newsgroup (there is no separate
comp.lang.ada.advocacy), and we want to make sure that everyone
realizes that Ada 83 is obsolete, and has been replaced (now
that the replacement is five years ago, and most Ada 83
compilers are no longer supported, that makes perfectly
reasonable sense).

Yes, we all understand that there are legacy systems using Ada
83, but it is interesting to note that DDCI, one of the last
vendors to be doing Ada 83 only, has recently validated Ada 95
compilers using the latest ACAATS tests (for which
congratulations are due, and it is definitely great to see a new
vendor joining the Ada 95 vendor industry, an industry where
competition is working well to improve the technology available
to Ada (95!) users.

In fact when people are using Ada 83, and ask how something is
to be done, it is always a good opportunity to point out that
what they are doing would be easier if they would not insist on
using an obsolete version of the language :-)

or, as often happens, they are are fact *using* Ada 95, but have
not learned how to use all the nice new features effectively!


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Type casting question
  1999-12-23  0:00             ` Larry Kilgallen
@ 1999-12-24  0:00               ` Robert Dewar
  0 siblings, 0 replies; 16+ messages in thread
From: Robert Dewar @ 1999-12-24  0:00 UTC (permalink / raw)


In article <1999Dec23.140120.1@eisner>,
  Kilgallen@eisner.decus.org.nospam wrote:
> You will notice a difference, however, in the degree to which
the Ada 95
> experts are able to relate to those who are not in their
position. Some
> of them are much more easygoing, for example Tucker Taft.


Certainly we are happy to answer Ada 83 questions when we know
that someone is limited to Ada 83, and from time to time we
do get questions of that kind :-) But the future of Ada depends
on Ada 95 (I don't think anyone sees much *future* in Ada 83,
though of course it is serving well in legacy programs [just
like Larry's pile of Vaxes :-)]

Robert Dewar


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~1999-12-24  0:00 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-20  0:00 Type casting question Raju Vemulamanda
1999-12-20  0:00 ` DuckE
1999-12-21  0:00 ` Robert Dewar
1999-12-21  0:00 ` Robert Dewar
1999-12-21  0:00   ` reason67
1999-12-21  0:00     ` Robert Dewar
1999-12-21  0:00       ` reason67
1999-12-22  0:00         ` Ted Dennison
1999-12-23  0:00         ` Robert Dewar
1999-12-23  0:00           ` reason67
1999-12-23  0:00             ` Robert Dewar
1999-12-23  0:00             ` reason67
1999-12-23  0:00             ` Robert Dewar
1999-12-23  0:00             ` Larry Kilgallen
1999-12-24  0:00               ` Robert Dewar
1999-12-21  0:00 ` David C. Hoos, Sr.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox