Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么可以';你不能在内核中使用科学符号吗_C_Linux Kernel_Scientific Notation - Fatal编程技术网

C 为什么可以';你不能在内核中使用科学符号吗

C 为什么可以';你不能在内核中使用科学符号吗,c,linux-kernel,scientific-notation,C,Linux Kernel,Scientific Notation,我试图编写一个内核(4.8.1)模块,如果我使用 if (hrtimer_cancel(&hr_timer) == 1) { u64 remaining = ktime_to_ns(hrtimer_get_remaining(&hr_timer)); printk("(%llu ns; %llu us)\n", remaining, (unsigned long long) (remaining/1e3)); } 这就产生了

我试图编写一个内核(4.8.1)模块,如果我使用

if (hrtimer_cancel(&hr_timer) == 1) {
         u64 remaining = ktime_to_ns(hrtimer_get_remaining(&hr_timer));
         printk("(%llu ns; %llu us)\n", remaining,
         (unsigned long long) (remaining/1e3));
}
这就产生了这个错误

error: SSE register return with SSE disabled
   printk("\t\t(%llu ns; %llu us)\n",
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          remaining,
          ~~~~~~~~~~
          (unsigned long long) (remaining/1e3));
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
如果我使用

if (hrtimer_cancel(&hr_timer) == 1) {
         u64 remaining = ktime_to_ns(hrtimer_get_remaining(&hr_timer));
         printk("(%llu ns; %llu us)\n", remaining,
         (unsigned long long) (remaining/1000));
}
它毫无问题地工作

那么为什么不能在内核中使用科学符号呢?我的意思是,我认为使用
1e3更容易、更可读;1e6;1e9
而不是
1000;1000000; 100000000

只是可移植性/健壮性的问题?
或者类似的(在这种情况下)

你需要打电话吗?使用
ktime\u\u\u ns

你需要我们吗?使用
ktime\u\u\u我们

你需要ms吗?使用
ktime\u-to\u-ms

另外,我尝试了一个简单的.c程序,它运行起来没有问题

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

void error_handler(const char *msg)
{
    perror(msg);
    exit(EXIT_FAILURE);
}

unsigned long parse_num(const char *number)
{
    unsigned long v;
    char *p;
    errno = 0;

    v = strtoul(number, &p, 10);

    if (errno != 0 || *p != '\0')
        error_handler("parse_num | strtoul");

    return v;
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        fprintf(stderr, "Usage: %s number_greater_than_1000\n", argv[0]);
        return EXIT_FAILURE;
    }

    unsigned long number = parse_num(argv[1]);

    if (number < 1e3 || number > 1e6)
    {
        fprintf(stderr, "Need to be a number in range (%lu, %lu)\n", (unsigned long) 1e3, (unsigned long) 1e6);
        return EXIT_FAILURE;
    }

    printf("Original: %lu\tScaled: %lu\n", number, (unsigned long) (number/1e3));

    return EXIT_SUCCESS;
}
#包括
#包括
#包括
#包括
无效错误\u处理程序(常量字符*msg)
{
佩罗尔(味精);
退出(退出失败);
}
无符号长解析数(常量字符*数字)
{
无符号长v;
char*p;
errno=0;
v=strtoul(编号和p,10);
如果(errno!=0 | |*p!='\0')
错误处理程序(“parse_num | strtoul”);
返回v;
}
int main(int argc,char*argv[])
{
如果(argc!=2)
{
fprintf(标准,“用法:%s编号大于\u 1000\n”,argv[0]);
返回退出失败;
}
无符号长数字=parse_num(argv[1]);
如果(编号<1e3 | |编号>1e6)
{
fprintf(stderr,“需要是范围(%lu,%lu)\n)”中的数字,(无符号长)1e3,(无符号长)1e6;
返回退出失败;
}
printf(“原件:%lu\t标度:%lu\n”,编号,(无符号长)(编号/1e3));
返回退出成功;
}
1e3
不等同于
1000

1000
是类型为
int
的整数常量
1e3
是类型为
double
的浮点常量,相当于
1000.0
。这使得
remaining/1e3
成为浮点除法,这正是编译器所抱怨的


另请参见。

我认为主要问题不在于符号,而在于
1e3
是一个
double
文字。为了节省寄存器的时间,内核通常不支持浮点运算。浮点运算可能重复