简体   繁体   English

如果使用 CLion 而不是直接使用 gcc 编译,C 程序的行为会有所不同。 为什么?

[英]C Program behaves differently if compiled using CLion rather than using gcc directly. Why?

I'm writing a program to play 4 in a row using C90.我正在编写一个使用 C90 连续播放 4 的程序。

I made a UI for the Console using ASCII characters.我使用 ASCII 字符为控制台制作了一个 UI。

If I compile the program using C Lion I get the following output:如果我使用 C Lion 编译程序,我会得到以下输出:

屏幕截图 C Lion 输出

If I compile it using gcc main.c and then run./a.out I get the following result:如果我使用 gcc main.c 编译它然后运行 ./a.out 我会得到以下结果:

截图终端输出

So obviously this dot character is sized differently if I compile it using gcc directly.所以很明显,如果我直接使用 gcc 编译它,这个点字符的大小会有所不同。

Has anyone any idea how this could possibly happen?有谁知道这怎么可能发生?

The code that is responsible for printing the game lines looks like this:负责打印游戏台词的代码如下所示:

void printGameLine(int line[7]) {
    int i;
    printf("┃");
    for (i = 0; i < 7; ++i) {
        printColor(line[i]);
        line[i] == 0 ? printf("    ") : printf(" ⬤ ");
        printColor(0);
        printf("┃");
    }
    printf("\n");
}

The code responsible for the colors looks like this: (If this makes any difference)负责颜色的代码如下所示:(如果这有什么不同的话)

/**
 * prints the color
 * @param player -1 First player, 0 neutral, 1 Second Player
 */
void printColor(int player) {
    switch (player) {
        case 1:
            printf("\033[0;31m"); /*red*/
            break;
        case -1:
            printf("\033[0;33m");/*yellow*/
            break;
        default:
            printf("\033[0m");/*neutral*/
            break;
    }
}

The issue is the font choice for the CLion Console.问题是 CLion 控制台的字体选择。

  • Go to File/[Settings...] then Editor/[Color Scheme]/[Console Font]转到文件/[设置...] 然后编辑器/[配色方案]/[控制台字体]
  • Disable the "Use console font instead of the default" checkbox禁用“使用控制台字体而不是默认字体”复选框
  • Choose a proper monospaced font of your choice (I use Fira Code)选择合适的等宽字体(我使用 Fira 代码)

配置截图

After that ensure to use same-length strings for both the empty and the "ball'd" positions.之后确保对空位置和“球”位置使用相同长度的字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C程序在gcc和llvm编译器中的行为有所不同 - C program behaves differently in gcc and llvm compiler 使用C89和C99编译时,C程序在运行时的行为有何不同? - What C program behaves differently in run-time when compiled with C89 and C99? 以可视c ++格式读取文件的行为与在C程序中读取行为不同 - Reading file with visual c++ form behaves differently than reading in C program 为什么GCC编译C程序需要.eh_frame部分? - Why GCC compiled C program needs .eh_frame section? 为什么使用GCC编译的程序不能使用DOSbox运行,而使用Borland(Turbo C)编译的程序却可以运行呢? - Why can't programs compiled using GCC be run using DOSbox while those compiled using Borland(Turbo C) can? 使用gcc -S选项编译C程序时,该字符串在汇编中如何表示? - How is this string in an array represented in assembly when a C program is compiled using the gcc -S option? 使用gcc编译C程序 - Using gcc to compile a C program 使用“在Windows上的Ubuntu上的Bash”编译的C脚本是否比直接在Windows上编译和运行慢? - Is a C script compiled using “Bash on Ubuntu on Windows” slower than directly compiling and running withing Windows? 为什么GCC / Clang在不同情况下的初始化行为不同? - Why GCC/Clang behaves differently on initialization in different cases? 通过使用 gcc 而不是 g++,output 二进制文件的大小更小 - The size of output binary is smaller by using gcc rather than g++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM