Typecast bug

2006-04-25 Thread zoltan
It is gcc 4.1.0, --target=arm-elf compiled on an Intel platform and
GNU/Linux.

The following construct:

void *p;

((char *)p)++;

makes the compiler to issue an error message, namely
"invalid lvalue in increment"

The ((char *)p) construct is perfectly valid object, a char pointer which
can be lvalue and rvalue alike. For some reason gcc 4.1.0 (and 4.0.2 as
well) treats ((SOME_TYPE *)p) as if it could not be an lvalue; older
versions treat the expression (as expected) as if p was a pointer to
SOME_TYPE instead of to void. This is true even if -std=c89 is specified,
and according to the old ANSI standard the above construct most definitely
is a valid lvalue.

Best Regards,

Zoltan






Re: Typecast bug

2006-04-26 Thread Gabriel Dos Reis
<[EMAIL PROTECTED]> writes:

| It is gcc 4.1.0, --target=arm-elf compiled on an Intel platform and
| GNU/Linux.
| 
| The following construct:
| 
| void *p;
| 
|   ((char *)p)++;
| 
| makes the compiler to issue an error message, namely
| "invalid lvalue in increment"
| 
| The ((char *)p) construct is perfectly valid object, a char pointer which
| can be lvalue and rvalue alike. For some reason gcc 4.1.0 (and 4.0.2 as
| well) treats ((SOME_TYPE *)p) as if it could not be an lvalue; 

indeed, it is not; in any ISO C version I know of.

-- Gaby


Re: Typecast bug

2006-04-26 Thread zoltan
On 26 Apr 2006, Gabriel Dos Reis wrote:

> <[EMAIL PROTECTED]> writes:
>
> | It is gcc 4.1.0, --target=arm-elf compiled on an Intel platform and
> | GNU/Linux.
> |
> | The following construct:
> |
> | void *p;
> |
> | ((char *)p)++;
> |
> | makes the compiler to issue an error message, namely
> | "invalid lvalue in increment"
> |
> | The ((char *)p) construct is perfectly valid object, a char pointer which
> | can be lvalue and rvalue alike. For some reason gcc 4.1.0 (and 4.0.2 as
> | well) treats ((SOME_TYPE *)p) as if it could not be an lvalue;
>
> indeed, it is not; in any ISO C version I know of.

OK - my bad. Wrote first thought later. Old gcc accepted the construct and
legacy code broke on the new compiler. My sincere apologies.

The question, however, remains: (how) can I tell the compiler to treat a
pointer declared as void *p; as if it was a SOME_TYPE *p pointer without
introducing temporaries?

Sorry again,

Thanks,

Zoltan




Re: Typecast bug

2006-04-27 Thread Gabriel Dos Reis
<[EMAIL PROTECTED]> writes:

| On 26 Apr 2006, Gabriel Dos Reis wrote:
| 
| > <[EMAIL PROTECTED]> writes:
| >
| > | It is gcc 4.1.0, --target=arm-elf compiled on an Intel platform and
| > | GNU/Linux.
| > |
| > | The following construct:
| > |
| > | void *p;
| > |
| > |   ((char *)p)++;
| > |
| > | makes the compiler to issue an error message, namely
| > | "invalid lvalue in increment"
| > |
| > | The ((char *)p) construct is perfectly valid object, a char pointer which
| > | can be lvalue and rvalue alike. For some reason gcc 4.1.0 (and 4.0.2 as
| > | well) treats ((SOME_TYPE *)p) as if it could not be an lvalue;
| >
| > indeed, it is not; in any ISO C version I know of.
| 
| OK - my bad. Wrote first thought later. Old gcc accepted the construct and
| legacy code broke on the new compiler. My sincere apologies.
| 
| The question, however, remains: (how) can I tell the compiler to treat a
| pointer declared as void *p; as if it was a SOME_TYPE *p pointer without
| introducing temporaries?

You have to use a cast, and the result is not an lvalue.  Period.

Or, use the original pointer SOME_TYPE *p.

-- Gaby