c - c 语言编程取决于操作系统

标签 c macos unix compiler-errors compilation

接下来就是问题了。我有一个工作的存储库和两台我编码的计算机。昨天我制作了一个可以在其中一台计算机上运行的程序,然后我在我的存储库中进行了推送。今天我已经下载了这个存储库的内容,但它无法编译。

代码可能取决于我的操作系统(一台机器有 OSX,另一台机器有 Ubuntu)。

谢谢

好的,这是代码:

#include <stdio.h>

enum chess {W, BL, WK, WQ, WP, WR, WH, WB ,BK, BQ, BP, BR, BH, BB};
static const char *chess_string[] = {"O", "X", "WK", "WQ", "WP", "WR", "WH", "WB" ,"BK", "BQ", "BP", "BR", "BH", "BB"};
typedef enum chess chess;

enum chess_letter {A,B,C,D,E,F,G,H};
static const char *chess_letter_string[] = {"A","B","C","D","E","F","G","H"};
typedef enum chess_letter chess_letter;

const int x=8;
const int y=8;

chess table [x][y];

void init_table(int x, int y, chess arr[x][y]){

    int i,j;

    int c=0;


    for(i=0;i<x;i++){
        for(j=0;j<y;j++){
            if(c==1){
                c=0;
                arr[i][j]=BL;
            }else{
                c=1;
                arr[i][j]=W;
            }
        }
        if(c==1){
            c=0;
        }else{
            c=1;
        }
    }
}

void print_table(int x, int y, chess arr[x][y]){

    int i;
    int j;

    printf("  ");
    for(i=0;i<x;i++){
        printf("%s  ",chess_letter_string[i]);
    }
    printf("\n");
    for(i=0;i<x;i++){
        printf("%d ",i+1);
        for(j=0;j<y;j++){
            printf("%s  ",chess_string[arr[i][j]]);
        }
        printf("\n");
    }

}

int main(){

    init_table(x,y,table);
    return 0;
}

它可以在 OSX 中运行,但不能在 Ubuntu 中运行。这是错误:

chess.c:14:7: error: variably modified ‘table’ at file scope
 chess table [x][y];
       ^
chess.c:14:7: error: variably modified ‘table’ at file scope

我使用gcc来编译它。

gcc chess.c -o chess

最佳答案

这只是版本问题。

关于c - c 语言编程取决于操作系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45208754/

相关文章:

linux - 如果它们出现在连续行中,则删除具有相似关键字的行

c - C 中的动态加载

c - printf 中的评估顺序和打印

c - 以下片段的输出是什么?

objective-c - 如何在沙盒 mac 应用程序中获取用户的图片目录?

java - 如何获取jar内的资源路径

使用字符串创建二叉搜索树

c - 带有指针的嵌套结构

objective-c - Xcode - UUID 与框架 dSYM 不匹配

unix - awk 错误 : "cannot open - too many open files"