Tag: gcc

浮点exception – gcc bug?

请考虑以下代码: #include #include int main() { #pragma STDC FENV_ACCESS ON 1.0/0.0; printf(“%x\n”, fetestexcept(FE_ALL_EXCEPT)); } 我希望它打印一个对应于FE_DIVBYZERO的非零值,但它会打印0.将main的第二行更改为double x = 1.0/0.0; 给出了预期的行为。 这是允许的,还是一个bug? 编辑:对于它的价值,起初似乎在大多数现实世界的代码中,可能导致引发fenvexception的操作无法优化,因此可以安全地执行大型计算并在最后检查是否有溢出,div-by-zero等发生了。 但是,当您考虑内联和优化时,事情会变得混乱,并且会出现真正的问题。 如果这样的函数在由于常量参数总是最终除以零的情况下被内联,那么gcc可能会变得非常聪明并优化整个内联函数,主要是为了return INFINITY; 没有提出任何例外。

为什么我的.c编码无法在GCC中编译?

我在c中有一个简单的代码: #include main() { printf(“Hello, world! /n”); } 但是我无法在GCC中编译它。 我尝试编译它时的警告: 1. gcc hello.c -o hello 2. hello.c: In function ‘main: 3. hello.c:4:1: error: stray ‘\342’ in program 4. hello.c:4:1: error: stray ‘\200’ in program 5. hello.c:4:1: error: stray ‘\234’ in program 6. hello.c:4:11: error: ‘Hello’ undeclared (first use in this function) 7. hello.c:4:11: note: each […]

ISO C等同于表达式中的支撑组

如何以兼容(ISO C99)方式执行以下操作? #define MALLOC(type, length, message) ({ \ type * a_##__LINE__ = (type *)malloc((length) * sizeof(type)); \ assert(message && (a_##__LINE__ != NULL)); \ a_##__LINE__; \ }) double **matrix = MALLOC(double *, height, “Failed to reserve”); 注意:要编译我使用:gcc -std = c99 -pedantic …

与单个进程方案相比,多进程方案中的访问时间意外较低

我从program1访问共享库(共享数组数据结构),并找到访问该时间来读取该数组的所有元素。 我得到大约17000个滴答,而只有Program1单独执行。 现在,当我首先在另一个选项卡中执行program2(具有空的while循环以保持终止)时,然后运行program1并测量访问时间以读取该数组的所有元素。 令我惊讶的是,与之前只有Program1执行的情况相比,我获得了8000ticks。 看起来只有program1执行时才需要花费更多时间来读取数组,而有2个程序时,program1正在执行与之前相同的任务,而program2通过while循环保持CPU忙。 预计存在program1的访问时间会更长,而实际结果则相反。 为什么会这样? 这是共享库 #include static const int DATA[1024]={1 ,2 ,3,…..1024]; inline void foo(void) { int j, k=0,count=0; for(j=0;j<1024;j++) { k=DATA[j]; } k+=0; } PROGRAM1 int main(void) { foo(); start=timer(); foo(); end=timer(); printf(“Time1=%llu\n”,end-start); start=timer(); foo(); end=timer(); printf(“Time2=%llu\n”,end-start); start=timer(); foo(); end=timer(); printf(“Time3=%llu\n”,end-start); sleep(1); start=timer(); foo(); end=timer(); printf(“after sleep(1)\n”); printf(“Time4=%llu\n”,end-start); start=timer(); foo(); end=timer(); […]

如何在c中乘以32位整数

执行: #define HIGH32(V64) ((uint32_t)((V64 >> 32)&0xffFFffFF)) #define LOW32(V64) ((uint32_t)(V64&0xffFFffFF)) uint32_t a = 0xffFFffFF; uint32_t b = 0xffFFffFF; uint64_t res = a * b; printf(“res = %08X %08X\n”, HIGH32(res), LOW32(res)); 得到: “res = 00000000 00000001” 但我期待:fffffffe00000001。 我做错了什么? 单一作业: res = 0x0123456789ABCDEF; printf(“res = %08X %08X\n”, HIGH32(res), LOW32(res)); 给 res = 01234567 89ABCDEF 环境: $gcc –version gcc […]

GCC最高指令集与多种架构兼容

我在由具有不同体系结构的计算机组成的集群上运行作业: gcc -march=native -Q –help=target | grep — ‘-march=’ | cut -f3 gcc -march=native -Q –help=target | grep — ‘-march=’ | cut -f3 gcc -march=native -Q –help=target | grep — ‘-march=’ | cut -f3给我其中一个: broadwell , haswell , ivybridge , sandybridge或skylake 。 可执行文件需要是相同的,所以我不能使用-march=native但同时架构有共同点(我认为它们都支持AVX?)。 我知道gcc (与Intel icc相反)不允许在单个可执行文件中存在多个目标。 我想知道的是,是否有办法向gcc询问与上面列出的所有架构兼容的最高指令集。 gcc版本:8.1.1

C:如何摆脱转换错误?

我有一个使用gcc版本4.6.3的项目,我被迫使用“-Wall -Werror -Wconversion”进行编译。 以下简单示例显示了我无法摆脱的错误: #include int main(void) { uint32_t u = 0; char c = 1; u += c; return (int)u; } 用上面的标志编译它给出: test.c:7:8: error: conversion to ‘uint32_t’ from ‘char’ may change the sign of the result [-Werror=sign-conversion] 好的。 只需添加一个类型转换,对吗? 不。 将第7行更改为u += (uint32_t)c不会使错误消失。 即使将其改为u = u + (uint32_t)c也不会让它消失。 有可能解决这个问题吗? 请注意,“char”来自字符串,因此我无法更改其类型。

使用ncurses在C中打印Unicode字符

我必须使用ncurses在C中绘制一个方框; 首先,为简单起见,我定义了一些值: #define RB “\e(0\x6a\e(B” (ASCII 188,Right bottom, for example) 我已经使用gcc编译,通过Ubuntu,使用-finput-charset=UTF-8标志。 但是,如果我尝试使用addstr或printw进行打印,我会得到hexa代码。 我做错了什么?

OS X上的Pthread和gcc编译问题

我有一个在Linux上编译好的脚本(Ubuntu 11.04),但在OS X(Lion)上没有。 gcc -pthread -o hw1 hw1.c hw1.c:22: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘barr’ hw1.c: In function ‘__syncthreads’: hw1.c:53: error: ‘barr’ undeclared (first use in this function) hw1.c:53: error: (Each undeclared identifier is reported only once hw1.c:53: error: for each function it appears in.) hw1.c:54: error: ‘PTHREAD_BARRIER_SERIAL_THREAD’ undeclared (first use […]

读取或写入的预取之间的区别

gcc文档讨论了读取的预取和写入的预取之间的区别。 有什么技术差异?