Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2003-07

AW: how to assign a value to an untyped variable

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ZINTEL Gerhard
Thank you both for your fast help. And of course I meant "value := r;"

I have found a third solution in the mean time (one should not give up to early:)
Do you know if that is in a machine independent way?

procedure test(var value);
var r : real absolute value;
begin
  r := 1.0;	// seems to work
end;
Show quoted text 31 lines
hello list members, could anyone of you give me a hint how to assign a value to an untyped variable parameter of a procedure. E.G. in the following procedure: procedure test(var value); var r : real; begin r := 1.0; value := real; // does not work end; which type to be used for a type cast (that is not allowed for the left side) or how to use an address operator to manage it? any help would be welcome gerhard ------------------------------- Gerhard Zintel Faurecia Abgastechnik GmbH Abt.: EGA Tel.: +49 911 7610171 Fax.: +49 911 7610350 e-mail: GZintel-AT-Stadeln.Faurecia.com _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
ZINTEL Gerhard
Show quoted text 14 lines
Hello all, Friday, July 11, 2003, 3:18:58 PM, you wrote: ZG> hello list members, ... ZG> which type to be used for a type cast (that is not allowed for the left ZG> side) or how to use an address operator to manage it? at least in my fpc 1.0.6 typecasts for the left side are allowed, value := r; // error real(value) := r; // works ! ;-)

In the (at least my) reference guide in chapter "6.4 Value typecasts" (version 1.8) there is written:

"Value typecasts cannot be used on the left side of assignments, as variable typecasts."

doesn't it mean that the above is not allowed or do I miss something?

Gerhard

Michael Van Canneyt
to ZINTEL Gerhard: In the (at least my) reference guide in chapter "6.4 Value typecasts" (version 1.8) there…
ZINTEL Gerhard wrote 22 lines
> > Hello all, > > Friday, July 11, 2003, 3:18:58 PM, you wrote: > > ZG> hello list members, > ... > ZG> which type to be used for a type cast (that is not > allowed for the left > ZG> side) or how to use an address operator to manage it? > at least in my fpc 1.0.6 typecasts for the left side are allowed, > value := r; // error > real(value) := r; // works ! ;-) > In the (at least my) reference guide in chapter "6.4 Value typecasts" (version 1.8) there is written: "Value typecasts cannot be used on the left side of assignments, as variable typecasts." doesn't it mean that the above is not allowed or do I miss something?

It means you cannot do

 TSomeType(1):=SomethingElse

as opposed to

 TSomeType(AVariable):=SomethingElse

Which means essentially that a typecast of a constant is still a constant, and cannot be assigned to. (same goes for expressions)

You can of course do
 SomethingElse:=TSomeType(1)

Michael.