invalid lvalue

P

Paul Edwards

The following code:

int main(void)
{
char *x;

(void **)x += 1;
return (0);
}

gives "invalid lvalue in assignment" when compiled with
the 64-bit Fedora Core 4 build of gcc 4.1.1.

But it works fine with other versions of gcc, and other compilers,
and the operation I want done looks entirely logical to me.

Is this code C90-compliant or not?

Thanks. Paul.
 
P

pete

Paul said:
The following code:

int main(void)
{
char *x;

(void **)x += 1;
return (0);
}

gives "invalid lvalue in assignment" when compiled with
the 64-bit Fedora Core 4 build of gcc 4.1.1.

But it works fine with other versions of gcc, and other compilers,
and the operation I want done looks entirely logical to me.

Is this code C90-compliant or not?

No.
The result of a type conversion, can't be an lvalue.
 
J

Joe Wright

Paul said:
The following code:

int main(void)
{
char *x;

(void **)x += 1;
return (0);
}

gives "invalid lvalue in assignment" when compiled with
the 64-bit Fedora Core 4 build of gcc 4.1.1.

But it works fine with other versions of gcc, and other compilers,
and the operation I want done looks entirely logical to me.

Is this code C90-compliant or not?

Thanks. Paul.
I can't imagine that code works anywhere. First x is defined a pointer
but doesn't point anywhere, its value is indeterminate. The result of a
cast can never be an lvalue.
 
C

CBFalconer

Paul said:
The following code:

int main(void) {
char *x;

(void **)x += 1;
return (0);
}

gives "invalid lvalue in assignment" when compiled with
the 64-bit Fedora Core 4 build of gcc 4.1.1.

But it works fine with other versions of gcc, and other compilers,
and the operation I want done looks entirely logical to me.

Is this code C90-compliant or not?

Not. The LHO is not a left-value. Looks like they improved gcc.
 
K

Keith Thompson

Joe Wright said:
I can't imagine that code works anywhere. First x is defined a pointer
but doesn't point anywhere, its value is indeterminate.

Right, and the result of operating on an indeterminate value needn't
be visibly bad.
The result of
a cast can never be an lvalue.

Unless the compiler supports it as an extension, as explicitly allowed
by C99 4p6. But a conforming compiler must still issue a diagnostic
<OT>as gcc will do when invoked with the correct options</OT>.
 
P

Paul Edwards

Joe Wright said:
I can't imagine that code works anywhere. First x is defined a pointer
but doesn't point anywhere, its value is indeterminate.

Well, the real code it is in has a defined value. This is just for
illustration.
The result of a cast can never be an lvalue.

Ok, thanks all. I'll change the code. The code in question is
actually in the obstack_ptr_grow() macro on line 426 of
include/obstack.h in gcc 3.2.3.

BFN. Paul.
 
A

Army1987

Paul Edwards said:
The following code:

int main(void)
{
char *x;

(void **)x += 1;
return (0);
}

gives "invalid lvalue in assignment" when compiled with
the 64-bit Fedora Core 4 build of gcc 4.1.1.

But it works fine with other versions of gcc, and other compilers,
and the operation I want done looks entirely logical to me.

Is this code C90-compliant or not?
No. The result of a cast isn't a lvalue.
see www.c-faq.com, question 4.5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top