c - 浮点异常C代码

标签 c exception floating-point wait

给定的代码产生浮点异常,谁能告诉我这是由什么引起的?

int play(t_env* env, t_pos* pos)
{
    pid_t   pid;
    int     ret;
    t_data  data;   
    int     status;

    pos->addx = 1;
    pos->addy = 0;
    pos->x = 2 + rand() % data.row;
    pos->y = 2 + rand() % data.col;
    pid = getpid();
    ret = waitpid(WAIT_ANY, &status, WNOHANG);

    if (ret == -1)
    {
            id_print_str("Error during waiting stat");
            exit(1);
    }
    while (pos->x != data.row)
    {
            tputs(tgoto(env->cm, pos->x, pos->y), 1, id_put);
            id_print_char('1');
            sleep(1);
            pos->x = pos->x + pos->addx;
            pos->y = pos->y + pos->addy;

    return (0);
}

最佳答案

根据给定的代码,我想,它只能在这里,

pos->x = 2 + rand() % data.row;
pos->y = 2 + rand() % data.col;

确保data.rowdata.col非零。否则,问题可能出在其他地方。

关于c - 浮点异常C代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7864252/

相关文章:

c++ - 使用可能抛出 C++ 的函数初始化 const 对象

c++ - 来自标准库调用的结构化异常 (SE)

math - float 学有问题吗?

在 C 中将 big int 转换为 float

c++ - 跨平台,具有异步能力的 C/C++ HTTP 库

c - 运行程序固定时间

在 C 中将 int 转换为字节数组?

c - 关于除数和和完美数的棘手且令人困惑的 C 程序

c++ - 为什么 std::istringstream 在不提升 failbit 标志的情况下生成错误的结果?

java - 线程 "main"java.lang.NoSuchMethodError : main 中的异常