1998 vintage C code now fails to compile under gcc

前端 未结 2 773
渐次进展
渐次进展 2021-01-13 11:48

I have ~16k lines of 1998 vintage C code (~50 main progs) which built flawlessly under gcc at that time but now fails with many \"lvalue required as left operand of assignme

2条回答
  •  深忆病人
    2021-01-13 12:23

    gcc is no longer allowing you to assign to a cast.

    i.e.

    ((CELL *)(cell)->car) = free_list;
    

    is no longer legal. Instead of casting the lhs to match the rhs, it would rather you cast the rhs to match the lhs. One way around this is to take the address of the lvalue, cast it as a pointer, and then dereference that pointer, so the assignment is to a pointer dereference instead of a cast.

    i.e.

    *((CELL **)&(cell)->car) = free_list;
    

    This can be handled by updating the macros, so it should be quite painless...

    i.e.

    #define cell_car(c)      (*((CELL **)&(c)->car))
    

    etc...

    This macro can then be used as either an lvalue or an rvalue.

提交回复
热议问题