Board index » delphi » invalid type casting question

invalid type casting question

I am usingl borland pascal:

procedure myfunc (s1,..: double);

myfunc1(x,s1);  <-- in here s1 should be inetger.
finally,
.
.
myfunc3(,..,param1,..);  <--In here param1 corresponds to
s1 and it is double.

Now what is the best way of type casting in here?.

I did invalid type casting when i did this:

procedure myfunc (s1,..: double);

var ss1:inetger;
.
.
ss1 := integer (s1)   <---type casting
myfunc1(x,ss1);
.
.
.
myfunc3(,..,param1,..)

--
Sent by   from yahoo in field com
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.com/cgi/content/new

 

Re:invalid type casting question


y_jim542...@yahoo.com wrote in <l.1012612837.1625244140@[63.127.215.130]>

[deleted]

Quote
> var ss1:inetger;
> .
> ss1 := integer (s1)   <---type casting

  Try this:

ss1:= Round(s1);

  Or may be you find more usefull function Int().

--
   Varyonov Konstantin       varkos^mail.ru      http://ghsrl.newmail.ru

Re:invalid type casting question


"Konstantin V. Varyonov" <var...@ktk.ru> wrote in message
news:01c1ac23$49c589c0$LocalHost@varkos...

Quote
> y_jim542...@yahoo.com wrote in <l.1012612837.1625244140@[63.127.215.130]>

> [deleted]
> > var ss1:inetger;
> > .
> > ss1 := integer (s1)   <---type casting

>   Try this:

> ss1:= Round(s1);

>   Or may be you find more usefull function Int().

> --
>    Varyonov Konstantin       varkos^mail.ru      http://ghsrl.newmail.ru

It might be useful to point out that casting in TP does not change data. If
you use Integer(v) where v is a variable of some type, that means "take the
first couple of bytes starting at the address of v and interpret them as an
integer".

From memory, my K&R is not to hand to check, but IIRC this could be the
source of some confusion to people coming from C, because that language uses
similar notation for casting as for type coercion.

So you can have a cast such as (char *)p where p is a pointer to something
other than char, that just reinterprets the memory occupied by p; but you
could also use (double)i to create a double with the value of the integer
variable i. That's a bit more involved than simply reinterpreting memory.

FP

Re:invalid type casting question


Frank Peelo wrote in <Amw78.33390$8s4.159...@news.indigo.ie>

[deleted]

Quote
> So you can have a cast such as (char *)p where p is a pointer to
something
> other than char, that just reinterprets the memory occupied by p; but you
> could also use (double)i to create a double with the value of the integer
> variable i. That's a bit more involved than simply reinterpreting memory.

  Pascal also can do same things:

=========== 1 ===========
type
  PChar = ^Char;

var
  P: Pointer;
  C: Char;

{...}
  C:= PChar(P)^;
{...}

=========== 2 ===========
var
  I: Integer;
  D: Double;

{...}

  D:= I; {or 1.0*I in expressions}

--
   Varyonov Konstantin       varkos^mail.ru      http://ghsrl.newmail.ru

Re:invalid type casting question


"Konstantin V. Varyonov" <var...@ktk.ru> wrote in message
news:01c1adaf$31933ea0$LocalHost@varkos...

Quote
> Frank Peelo wrote in <Amw78.33390$8s4.159...@news.indigo.ie>

> [deleted]
> > So you can have a cast such as (char *)p where p is a pointer to
> something
> > other than char, that just reinterprets the memory occupied by p; but
you
> > could also use (double)i to create a double with the value of the
integer
> > variable i. That's a bit more involved than simply reinterpreting
memory.

>   Pascal also can do same things:

> =========== 1 ===========
> type
>   PChar = ^Char;

> var
>   P: Pointer;
>   C: Char;

> {...}
>   C:= PChar(P)^;
> {...}

> =========== 2 ===========
> var
>   I: Integer;
>   D: Double;

> {...}

>   D:= I; {or 1.0*I in expressions}

Of course it can, but my point was that in Pascal the latter example is not
a cast. I think we have a bigger distinction between typecasting and type
conversion than C programmers.

FP

Other Threads