Pelles C forum

C language => Beginner questions => Topic started by: alexei on September 04, 2010, 11:29:49 AM

Title: Problem with "Lvalue required"
Post by: alexei on September 04, 2010, 11:29:49 AM
Other compilers are OK with this (see code below). Is it because of ANSI?
Is there a way to do such things without re-declaring variables?
I mean typecasting any variable to any type.

Code: [Select]
int main (int argc, char *argv[])
{
  unsigned z;
  void* p;
  (int)z = (int)z-5;
  (int)p = (int)p+2;
  return 0;
}
Test.c(5): error #2088: Lvalue required.
Test.c(6): error #2088: Lvalue required.
Title: Re: Problem with "Lvalue required"
Post by: JohnF on September 04, 2010, 12:47:39 PM
Other compilers are OK with this (see code below). Is it because of ANSI?
Is there a way to do such things without re-declaring variables?
I mean typecasting any variable to any type.

Test.c(5): error #2088: Lvalue required.
Test.c(6): error #2088: Lvalue required.

The answer is no. You can sometimes cast the right side so that it matches the left side but you can never cast the left side or change a variable into a different type.

Code: [Select]
float f = 1.0;
 int i;
 i = (int)f;

John
Title: Re: Problem with "Lvalue required"
Post by: Juni on September 08, 2010, 10:06:17 AM
Just curious wich compiler do you mean ?