【发布时间】:2017-12-25 19:10:53
【问题描述】:
问题是下一个。我有一个我工作的存储库和两台我编码的计算机。昨天我制作了一个可以在其中一台计算机上运行的程序,然后我在我的存储库中进行了推送。今天我已经下载了这个存储库的内容,但它没有编译。
代码可能取决于我的操作系统(一台机器有 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
【问题讨论】:
-
如果您使用特定于操作系统的功能,那么是的,当然代码取决于操作系统。另请注意,基本上剩下 Unix 的两个变体,BSD(macOS 是其中的一个变体)和SYSV(Linux 主要继承自其中)。两种变体之间存在细微差异,可能会导致问题。如果没有更多细节(最好是Minimal, Complete, and Verifiable Example),就不可能更具体。
-
很有可能,但是用这么少的细节回答一个问题是不可能的。你能分享一些代码和你得到的错误吗?
-
即使您不使用特定于操作系统的函数,它也可能取决于编译器特定的扩展。或者编译器之间对standard C的支持是不同的。不可能回答你可能做错了什么。
-
您的问题的答案是:是的。如果你想要更多细节,你至少需要提供你得到的编译器的错误信息。
-
“触摸”一切,重建一切。
标签: c macos unix compiler-errors compilation