2017-07-20 27 views
-7

問題在於下。我有一個存儲庫,我工作的地方和兩臺我編碼的計算機。昨天我製作了一個適用於這臺計算機的程序,然後我推送了一個存儲庫。今天我已經下載了這個倉庫的內容,但是它不能編譯。用c編程取決於操作系統

它可能代碼取決於我的操作系統(一臺機器有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 
+3

如果您使用操作系統特定的功能,那麼當然代碼取決於操作系統。還要注意,基本上有兩種Unix版本,[BSD](https://en.wikipedia.org/wiki/Berkeley_Software_Distribution)(其中macOS是變體)和[SYSV](https://en.wikipedia .org/wiki/UNIX_System_V)(其中Linux主要繼承自)。兩種變體之間可能會導致問題,這些差異很小。沒有更多細節(並且最好是[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)),不可能更具體。 –

+1

很有可能,但用這麼少的細節回答問題是不可能的。你能分享一些代碼和你得到的錯誤嗎? – Mureinik

+3

即使您不使用特定於操作系統的函數,也可能依賴於特定於編譯器的**擴展**。或者編譯器對*標準C *的支持不同。回答你可能做錯的事情是不可能的。 – StoryTeller

回答

0

這只是一個版本問題。