0

第一个问题:我正在尝试导入 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 的不同方法,但没有任何效果,只有垃圾。

谢谢你的任何答案。

4

1 回答 1

1

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

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

有效!

于 2014-11-21T15:01:17.983 回答