我没有做太多的c编程,我遇到了“错误:取消对不完整类型的指针引用”。正在尝试通过调用clock_gettime来清除gettimeofday。
以下是代码
#include <time.h>
int gettimeofday(struct timeval *tv, struct timezone *tz)
/* This procedure stubs out call to gettimeofday */
{
struct timespec spec;
// initialize result status to invalid
int result = -1;
// if passed in pointer tv is not NULL
if (tv) {
// retrieve time
result = clock_gettime(CLOCK_REALTIME, &spec);
// if time retreived is valid then
if (result == 0){
tv->tv_sec = spec.tv_sec; // seconds
tv->tv_usec = (spec.tv_nsec / 1.0e3); // Convert nanoseconds to microseconds
}
}
return result;
}我在赋值时得到“解除对不完整类型的指针的引用时出错”
tv->tv_sec = spec.tv_sec; // seconds 如果我在linux target=i686-pc-linux-gnu中编译/link,但没有错误,则intarget=powerpc-xcoff-lynxos178目标环境。
我是#include,它有定义的timespec
每个目标的time.h是不同的。感谢您花时间看这篇文章。
发布于 2020-03-18 04:55:06
在需要#include <sys/time.h>的同时,您可能会看到与系统的gettimeofday()调用的原型发生冲突。在许多系统上,第二个参数是void *。
发布于 2020-03-20 00:46:40
这个gettimeofday存根的问题是,我们试图编写在3个不同环境中工作的存根。Windows、Linux目标和powerpc目标--它们似乎在操作系统头文件中都有一些细微的变化。我们最终做的是添加一个编译器指令来处理linux和其他我们没有问题的环境。这就是我们最终选择的方法--我认为我们应该避免使用存根,只使用clock_gettime,但这种方式更便宜是有原因的。
#include <time.h>
#include <sys/time.h>
#ifdef __linux__
int gettimeofday(struct timeval *__restrict __tv, __timezone_ptr_t __tz)
#else
int gettimeofday(struct timeval * __tv, struct timezone* __tz)
#endifhttps://stackoverflow.com/questions/60714789
复制相似问题