1998 vintage C代码现在无法在gcc下编译 [英] 1998 vintage C code now fails to compile under gcc

查看:114
本文介绍了1998 vintage C代码现在无法在gcc下编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大约1.6万行1998年的老式C代码(〜50个主编),当时在gcc下完美构建,但现在在第一个例程口吃"中出现了许多需要左值作为赋值左赋值"错误. C".我还没有足够的C程序员来发现问题,并且似乎无法在Internet上针对我的问题找到答案(带有此相当普通的错误消息).

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 assignment" errors in the first routine, "stutter.c". I'm not enough of a C programmer to find the problem and can't seem to search out an answer on the internet specific to my problem (with this rather generic error message).

以下是详细信息:

从(老式)Makefile编译行:

Compile line from the (vintage) Makefile:

gcc -O3 -Wall -D__dest_os = unix -I/usr/X11/include -DPLOTX11 -c -o stutter.o ../src/stutter.c

gcc -O3 -Wall -D__dest_os=unix -I/usr/X11/include -DPLOTX11 -c -o stutter.o ../src/stutter.c

失败语句示例:

    cell_car(cell) = free_list;
    cell_type(cell) = type;
    cell_name(atom) = strdup(name);
    cell_cdr(list) = binding_list;
    cell_cdr(cell_car(current)) = b;

...(以及许多类似的内容)

... (and many similar)

之前:

    typedef enum CELL_ENUM {
      CELL_LAMBDA, CELL_SFUNC, CELL_VFUNC, CELL_LIST, CELL_ATOM
    } CELL_TYPE;

    typedef struct CELL_STRUCT {
    void *car, *cdr;
    unsigned type : 7;
    unsigned mark : 1;
    char empty[3];
    } CELL;

和:

    #define cell_car(c)      ((CELL *)(c)->car)
    #define cell_cdr(c)      ((CELL *)(c)->cdr)        
    #define cell_name(c)     ((char *)(c)->car)
    #define cell_func(c)     ((CELL *(*)())(c)->car)
    #define cell_type(c)     ((CELL_TYPE)(c)->type)
    #define cell_mark(c)     ((c)->mark)

如果需要,可以提供更多代码细节.这里有一些明显不推荐使用的功能来解释此错误吗?

More code particulars available if needed. Is there some obvious deprecated feature here which explains this error??

我有多年的科学Fortran程序员经验,但是在学习足够的C语言以完全进行转换之前已经退休.在 http://gcc.gnu.org/bugs/上没有发现有关遗留代码的任何帮助.我将不胜感激,因为这些帮助可以使我在当前项目的linux下运行这些例程之前,不必完成C,C ++和gcc教育.非常感谢!

I have many years of experience as a scientific Fortran programmer but retired before learning enough of C to completely make the switch. Haven't found anything helpful about legacy code at http://gcc.gnu.org/bugs/. I'd appreciate any help that would save me having to complete my C, C++ and gcc education before I get these routines working under linux for my current project. Thanks much!

推荐答案

gcc不再允许您分配演员.

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

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

不再合法.与其将lhs转换为与rhs相匹配,不如您将rhs转换为与lhs相匹配.解决此问题的一种方法是获取左值的地址,将其强制转换为指针,然后取消对该指针的引用,因此分配是指针取消引用而不是强制转换.

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.

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

这可以通过更新宏来处理,因此应该很轻松...

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

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

等...

此宏随后可用作左值或右值.

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

这篇关于1998 vintage C代码现在无法在gcc下编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆