#65 Extension for cast as an lvalue

open
nobody
None
5
2004-02-26
2004-02-26
Bernhard Held
No

void *voidptr;

void foo (void)
{
((unsigned int *)voidptr)++;
}

'lvalue' required for '++' operation.

Discussion

  • Erik Petrich
    Erik Petrich
    2004-02-26

    Logged In: YES
    user_id=635249

    I've changed this to a feature request since the compiler is
    giving an appropriate error message to an illegal expression.
    K&R 2nd ed states "An expression with a cast is not an
    lvalue." (section A7.5). ISO/IEC 9899:1999 concurs "A cast
    does not yield an lvalue." (section 6.5.4).

     
  • Erik Petrich
    Erik Petrich
    2004-02-26

    • labels: 101552 -->
    • summary: pointer cast problem --> Extension for cast as an lvalue
     
  • Hubert Sack
    Hubert Sack
    2004-12-05

    Logged In: YES
    user_id=1160854

    There is a very simple solution for your problem:

    *((unsigned int**)&voidptr)++;

     
  • Hubert Sack
    Hubert Sack
    2004-12-05

    Logged In: YES
    user_id=1160854

    There is a very simple solution for your problem:

    *((unsigned int**)&voidptr)++;