c编程取决于操作系统

时间:2017-07-20 07:57:31

标签: c macos unix compiler-errors compilation

问题是下一个问题。我有一个我工作的存储库,以及我编码的两台计算机。昨天我制作了一个适用于其中一台计算机的程序,然后我在我的存储库中进行了推送。今天我已经下载了这个存储库的内容,但它没有编译。

代码可能依赖于我的操作系统(一台机器有OSX和其他Ubuntu)。

由于

好的,这是代码:

In [57]: x
Out[57]: array([0, 1, 2, 3, 4])

In [58]: y
Out[58]: array([1, 3, 1, 4, 2])

In [59]: data = np.repeat(x,y)

In [65]: data
Out[65]: array([0, 1, 1, 1, 2, 3, 3, 3, 3, 4, 4])

In [60]: np.mean(data)
Out[60]: 2.2727272727272729

In [61]: np.median(data)
Out[61]: 3.0

In [62]: np.inner(x,y)/float(y.sum())
Out[62]: 2.2727272727272729

它适用于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;
}

我用gcc编译它。

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

1 个答案:

答案 0 :(得分:0)

这只是一个版本问题。