【问题标题】:problems compiling and running Nachos编译和运行 Nachos 的问题
【发布时间】:2014-11-07 07:34:33
【问题描述】:

第一个问题:我正在尝试导入 stdlib.h 以使用 malloc() 和 rand() 等函数。我在 threadtest.cc 工作,文件夹线程。这是我在

之后得到的错误
#include <stdlib.h>

In file included from ../threads/threadtest.cc:18:0:
/usr/include/stdlib.h:146:33: error: declaration of ‘double atof(const char*) throw ()’ has a different exception specifier
In file included from ../threads/utility.h:57:0,
             from ../threads/system.h:12,
             from ../threads/threadtest.cc:13:
../machine/sysdep.h:62:8: error: from previous declaration ‘double atof(const char*)’
In file included from ../threads/threadtest.cc:18:0:
/usr/include/stdlib.h:149:33: error: declaration of ‘int atoi(const char*) throw ()’ has a different exception specifier
In file included from ../threads/utility.h:57:0,
             from ../threads/system.h:12,
             from ../threads/threadtest.cc:13:
../machine/sysdep.h:61:5: error: from previous declaration ‘int atoi(const char*)’
In file included from ../threads/threadtest.cc:18:0:
/usr/include/stdlib.h:771:60: error: declaration of ‘int abs(int) throw ()’ has a different exception specifier
In file included from ../threads/utility.h:57:0,
             from ../threads/system.h:12,
             from ../threads/threadtest.cc:13:
../machine/sysdep.h:63:5: error: from previous declaration ‘int abs(int)’
../threads/threadtest.cc: In function ‘void shout(int)’:
../threads/threadtest.cc:83:25: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

这可能是什么原因?

第二个问题:我正在尝试为分叉的新线程命名。

Thread * t = new Thread ("my id");
t->Fork(shout, S);

并在函数呼喊中对其进行测试:

printf ("%s", currentThread->getName());

这个例子运行良好。 但是,如果我想给线程一个“动态”ID,我使用:

sprintf(id, "%d", i);
Thread * t = new Thread (id);

对于 currentThread->getName() 使用相同的 printf,它让我很垃圾:

x�ӿ����_ ���

我使用了 Nachos 文档中的示例,并尝试了使用字符串函数传输动态 id 的不同方法,但没有任何效果,只有垃圾。

感谢您的任何回答。

【问题讨论】:

    标签: nachos


    【解决方案1】:

    我在玉米片作业中遇到了同样的问题。

    我室友说可能是不兼容的问题,建议我删除“stdlib.h”。

    成功了!

    【讨论】:

      猜你喜欢
      • 2016-03-08
      • 2011-01-16
      • 1970-01-01
      • 2010-10-18
      • 2019-03-25
      • 1970-01-01
      • 1970-01-01
      • 2021-07-10
      • 2016-02-09
      相关资源
      最近更新 更多