Re: variable type cast

Tom Verhoeff <[email protected]>
Newsgroups gmane.comp.compilers.gpc
Message-ID <[email protected]>
On Sun, May 12, 2013 at 04:12:45PM -0700, Jay Michael wrote:
> gpc version 20070904, based on gcc-3.4.5 (mingw special)
>  
>      Given
>           type INT16  = INTEGER  attribute( size=16 ) ;
>           type WORD16 = Cardinal attribute( size=16 ) ;
>           var i16 : INT16 ;
>           var w16 : WORD16 ;
> why does
>           WORD16(I16) := W16 ;
> produce "error: invalid lvalue in assignment"?

I would think that the reason is that to the left of the assignment
operator you need a variable or equivalent, in C jargon also known
as an lvalue (i.e. something that has a persistent memory address).

Note that a variable by itself is both an lvalue and an expression (an
rvalue, though this term is little used), but not every expression is
an lvalue (e.g. v + 1 is not an lvalue; you cannot assign anything to it).

In particular, casting is an operator that yields an rvalue, but not
an lvalue.  Casting needs to done to the right of the assignment operator.

(The previous warnings about casting still stand.)

	Tom
-- 
E-MAIL: T.Verhoeff (a) TUE.NL   | Dept. of Math. & Comp. Science
PHONE:  +31 40 247 41 25        | Eindhoven University of Technology
FAX:    +31 40 247 54 04        | PO Box 513, NL-5600 MB Eindhoven
http://www.win.tue.nl/~wstomv/  | The Netherlands

_______________________________________________
Gpc mailing list
[email protected]
https://www.g-n-u.de/mailman/listinfo/gpc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.