命令提示冻结GCC编译

时间:2014-02-10 02:24:15

标签: c windows gcc command-prompt freeze

我不是编程的超级初学者,但我通过windows命令提示符窗口编译和运行代码相对较新。

#include <stdio.h>
int main(){
double LATER = 0, EARLIER = 0, RESULT = 0; // Declare and initialize LATER and EARLIER
                                           //to store operands and RESULT to hold a 
                                           //calculated result. Declare as type double.
char COMMAND = ' ';         // Declare COMMAND to store the last entered character. 
return 0;}
/*
while !(COMMAND == 'q')
{
    printf("Please enter operand(s), and/or an operator. \n (For division and  subtraction, ensure that the numerator or minuend is entered first): \n");
    scanf("%lf %lf %c \n",&EARLIER,&LATER,&OPERATOR); // Read in large float values for EARLIER and LATER and a character value for OPERAND
    printf("= %.3lf", RESULT);
}
*/

每当我编译它(GCC)并尝试运行它时,我的命令提示符会冻结 - 也就是说,它不接受任何输入,只是作为黑屏(仍然显示先前的控制台输出)。任何人都知道我应该怎么做才能解决这个问题?

更新:试图从CodeBlocks运行相同的东西,并遇到同样的问题。弹出两个控制台窗口,一个运行代码并关闭,另一个卡住并且不会关闭。如果没有重启,仍然无法再次运行程序。

2 个答案:

答案 0 :(得分:0)

好问题。我坚信这是GCC win32(在我的案例中为MinGW)中的一个错误,虽然细节很难确定,所以我不确定是否存在针对它的现有错误报告或我的错误在这里引用它。它似乎影响的人很少,因为我在其他地方没有看到它。

证据我有一个复杂的运行应用程序,我已经开发了一段时间;但是偶尔,即使进行了一个微不足道的增量更改(一行,无错误),GCC也会锁定命令提示符(具有管理员权限),有时可以关闭,而其他时候既不关闭按钮也不关闭任务管理器也不是Windows关闭可以释放进程;尝试在另一个命令提示符下运行GCC同样失败。然后我必须强行重启。重新启动后,必须清除某种缓存或gcc应用程序状态,因为编译然后会顺利关闭。 gcc -v返回:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=m
ingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto
--enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++
,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-l
ibstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gm
p-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --
with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-
libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/
mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)

P.S。根据this question,GCC可能已锁定等待内核资源。这可能是由于它试图访问Windows内核资源而不是Linux的方式,因为它已经从后者移植过来。

P.P.S。如果这不是GCC错误,那么OP和我有一些共同的操作系统问题。

答案 1 :(得分:-1)

问题中的代码只是:

  • 声明double变量LATEREARLIERRESULT
  • 将其初始化为0
  • 声明char变量COMMAND
  • 将其初始化为单个空格字符。
  • 成功退出(返回值为0
  

因此您看到的是一个空的控制台。

查看相同代码的正确缩进列表。请注意,main()函数在return 0;之后的行结束。此行之后的所有内容都是多行注释,其输出二进制文件中未生成executabel指令。

#include <stdio.h>

int main()
{

    double LATER = 0, EARLIER = 0, RESULT = 0;
    // Declare and initialize LATER and EARLIER
    //to store operands and RESULT to hold a 
    //calculated result. Declare as type double.

    // Declare COMMAND to store the last entered character. 
    char COMMAND = ' ';

    return 0;
}

/*
   while !(COMMAND == 'q') {
    printf("Please enter operand(s), and/or an operator. \n"
           "(For division and  subtraction,"
           " ensure that the numerator or minuend is entered first):");

    // Read in large float values for EARLIER and LATER and a character value for OPERAND
    scanf("%lf %lf %c \n",&EARLIER,&LATER,&OPERATOR);

   printf("= %.3lf", RESULT);
}
*/

您需要在以下代码的行中执行以下操作:

  1. 接受3个输入。

  2. 执行一些操作以获得结果。

  3. 如果第三个输入是字符“q”则退出,否则再次请求3个输入。

  4. 缺少 Step2 的代码。它是你的TODO; - )

    #include <stdio.h>
    
    int main()
    {
    
        // Declare and initialize LATER and EARLIER
        //to store operands and RESULT to hold a 
        //calculated result. Declare as type double.
        double earlier = 0, later = 0, result = 0;
    
        // Declare COMMAND to store the last entered character. 
        char cmd = ' ';
    
        while (cmd != 'q') {
            printf("Please enter the following 3\n"
                   "< operand1 operand2 operator >\n"
                   "(For division and  subtraction,"
                   " ensure that the numerator or minuend is entered first):\n");
    
            // Read in large float values for EARLIER and LATER and a character value for OPERAND
            scanf("%lf %lf %c", &earlier, &later, &cmd);
    
            // TODO: Add code to calculate "result" here
    
            // Print "result"
            printf("result= %.3lf\n", result);
        }
    
        return 0;
    }