Tag: gcc

升级到Mojave后无法在Mac上编译C程序

我在终端上使用了gcc命令来编译C程序但突然间,在我的Mac操作系统更新后(到macOS 10.14 Mojave和XCode 10.0),我开始收到消息: test.c:8:10: fatal error: stdio.h: No such file or directory #include ^~~~~~~~~ compilation terminated. 我已经安装了gcc,因为我可以在/usr/local/bin找到它并且那里确实有一个gcc。 我尝试在我的其他iMac上运行相同的文件,它没有任何问题。 我尝试运行xcode-select –install并且它已经安装,因此它没有解决我现在遇到的问题。 我猜测路径搞砸了,因为在我开始复制并粘贴其他资源中的一些命令来解决此问题后,它似乎无法找到gcc 。 希望对此有所帮助。

检测二进制文件的GCC编译时标志

有没有办法找出编译特定二进制文件的gcc标志?

奇怪的数组初始化表达式?

以下代码是什么意思? 代码来自GCC的回归测试套件。 static char * name[] = { [0x80000000] = “bar” };

使用内联汇编在数组上循环

当使用内联汇编循环数组时,我应该使用寄存器修饰符“r”还是内存修饰符“m”? 让我们考虑一个添加两个浮点数组x和y并将结果写入z的示例。 通常我会使用内在函数这样做 for(int i=0; i<n/4; i++) { __m128 x4 = _mm_load_ps(&x[4*i]); __m128 y4 = _mm_load_ps(&y[4*i]); __m128 s = _mm_add_ps(x4,y4); _mm_store_ps(&z[4*i], s); } 这是我使用寄存器修饰符“r”提出的内联汇编解决方案 void add_asm1(float *x, float *y, float *z, unsigned n) { for(int i=0; i<n; i+=4) { __asm__ __volatile__ ( "movaps (%1,%%rax,4), %%xmm0\n" "addps (%2,%%rax,4), %%xmm0\n" "movaps %%xmm0, (%0,%%rax,4)\n" : : "r" (z), […]

c99转到过去的初始化

在调试崩溃时,我在一些代码中遇到了这个问题: int func() { char *p1 = malloc(…); if (p1 == NULL) goto err_exit; char *p2 = malloc(…); if (p2 == NULL) goto err_exit; … err_exit: free(p2); free(p1); return -1; } 第一个malloc失败时会出现此问题。 因为我们跳过p2的初始化,它包含随机数据,并且对free(p2)的调用可能会崩溃。 我希望/希望这将与C ++中的方式相同,其中编译器不允许goto跳过初始化。 我的问题:是跳过标准允许的初始化还是这是gcc实现c99的错误?

C编译失败:找不到math.h函数

我正在写一个素数发现者。 在数学上,它更快,而不是for (unsigned long i = 2; i < number/2; i++)它更快,并且仍然同样有效, for (unsigned long i = 2; i < sqrt(number); i++) 但它不起作用。 以下是我的代码。 // Stuff goes up here, including a function prototype and: #include char isPrime (unsigned long number) { if (number <= 1) { return 0; } long double sqrtOfNumber = sqrt(number); // Calculate […]

gcc结构中的内存对齐

我将应用程序移植到C中的ARM平台,该应用程序也在x86处理器上运行,并且必须向后兼容。 我现在有一些变量对齐的问题。 我已经阅读了__attribute__((aligned(4),packed))的gcc手册__attribute__((aligned(4),packed))我解释了所说的内容,因为struct的开头与4字节边界对齐,并且由于packed语句,内部保持不变。 最初我有这个,但偶尔它与4字节边界不对齐。 typedef struct { unsigned int code; unsigned int length; unsigned int seq; unsigned int request; unsigned char nonce[16]; unsigned short crc; } __attribute__((packed)) CHALLENGE; 所以我把它改成了这个。 typedef struct { unsigned int code; unsigned int length; unsigned int seq; unsigned int request; unsigned char nonce[16]; unsigned short crc; } __attribute__((aligned(4),packed)) CHALLENGE; 我之前说过的理解似乎是不正确的,因为结构现在都与4字节边界对齐,并且内部数据现在与4字节边界对齐,但由于字节顺序,结构的大小增加了大小从42到44个字节。 这个大小是至关重要的,因为我们有其他依赖于结构为42字节的应用程序。 […]

如何在gcc中实现变量参数?

int max(int n, …) 我正在使用cdecl调用约定,其中调用者在被调用者返回后清理变量。 我有兴趣知道宏va_end , va_start和va_arg工作的? 调用者是否将参数数组的地址作为max的第二个参数传递?

如何在没有编译器浪费指令归零上层元素的情况下将标量合并到向量中? 英特尔内在函数的设计限制?

我没有特定的用例; 我问这是否真的是英特尔内在函数中的设计缺陷/限制,或者我是否只是遗漏了某些内容。 如果你想将标量浮点数与现有向量相结合,那么使用英特尔内在函数时,如果没有高元素归零或将标量广播到向量中,似乎没有办法实现。 我没有研究过GNU C本机向量扩展和相关的内置函数。 如果额外的内在优化,这不会太糟糕,但它不与gcc(5.4或6.2)。 使用pmovzx或insertps作为载荷也没有好的方法,因为它们的内在函数只采用向量args的相关原因。 (并且gcc不会将标量 – >向量加载到asm指令中。) __m128 replace_lower_two_elements(__m128 v, float x) { __m128 xv = _mm_set_ss(x); // WANTED: something else for this step, some compilers actually compile this to a separate insn return _mm_shuffle_ps(v, xv, 0); // lower 2 elements are both x, and the garbage is gone } gcc 5.3 […]

使用GNU C内联汇编在VGA内存中绘制字符

我正在学习用DOS和内联汇编在DOS下进行一些低级VGA编程。 现在我正在尝试创建一个在屏幕上打印出一个角色的function。 这是我的代码: //This is the characters BITMAPS uint8_t characters[464] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x00,0x20,0x00,0x50, 0x50,0x00,0x00,0x00,0x00,0x00,0x50,0xf8,0x50,0x50,0xf8,0x50,0x00,0x20,0xf8,0xa0, 0xf8,0x28,0xf8,0x00,0xc8,0xd0,0x20,0x20,0x58,0x98,0x00,0x40,0xa0,0x40,0xa8,0x90, 0x68,0x00,0x20,0x40,0x00,0x00,0x00,0x00,0x00,0x20,0x40,0x40,0x40,0x40,0x20,0x00, 0x20,0x10,0x10,0x10,0x10,0x20,0x00,0x50,0x20,0xf8,0x20,0x50,0x00,0x00,0x20,0x20, 0xf8,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x60,0x20,0x40,0x00,0x00,0x00,0xf8,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x08,0x10,0x20,0x40,0x80, 0x00,0x70,0x88,0x98,0xa8,0xc8,0x70,0x00,0x20,0x60,0x20,0x20,0x20,0x70,0x00,0x70, 0x88,0x08,0x70,0x80,0xf8,0x00,0xf8,0x10,0x30,0x08,0x88,0x70,0x00,0x20,0x40,0x90, 0x90,0xf8,0x10,0x00,0xf8,0x80,0xf0,0x08,0x88,0x70,0x00,0x70,0x80,0xf0,0x88,0x88, 0x70,0x00,0xf8,0x08,0x10,0x20,0x20,0x20,0x00,0x70,0x88,0x70,0x88,0x88,0x70,0x00, 0x70,0x88,0x88,0x78,0x08,0x70,0x00,0x30,0x30,0x00,0x00,0x30,0x30,0x00,0x30,0x30, 0x00,0x30,0x10,0x20,0x00,0x00,0x10,0x20,0x40,0x20,0x10,0x00,0x00,0xf8,0x00,0xf8, 0x00,0x00,0x00,0x00,0x20,0x10,0x08,0x10,0x20,0x00,0x70,0x88,0x10,0x20,0x00,0x20, 0x00,0x70,0x90,0xa8,0xb8,0x80,0x70,0x00,0x70,0x88,0x88,0xf8,0x88,0x88,0x00,0xf0, 0x88,0xf0,0x88,0x88,0xf0,0x00,0x70,0x88,0x80,0x80,0x88,0x70,0x00,0xe0,0x90,0x88, 0x88,0x90,0xe0,0x00,0xf8,0x80,0xf0,0x80,0x80,0xf8,0x00,0xf8,0x80,0xf0,0x80,0x80, 0x80,0x00,0x70,0x88,0x80,0x98,0x88,0x70,0x00,0x88,0x88,0xf8,0x88,0x88,0x88,0x00, 0x70,0x20,0x20,0x20,0x20,0x70,0x00,0x10,0x10,0x10,0x10,0x90,0x60,0x00,0x90,0xa0, 0xc0,0xa0,0x90,0x88,0x00,0x80,0x80,0x80,0x80,0x80,0xf8,0x00,0x88,0xd8,0xa8,0x88, 0x88,0x88,0x00,0x88,0xc8,0xa8,0x98,0x88,0x88,0x00,0x70,0x88,0x88,0x88,0x88,0x70, 0x00,0xf0,0x88,0x88,0xf0,0x80,0x80,0x00,0x70,0x88,0x88,0xa8,0x98,0x70,0x00,0xf0, 0x88,0x88,0xf0,0x90,0x88,0x00,0x70,0x80,0x70,0x08,0x88,0x70,0x00,0xf8,0x20,0x20, 0x20,0x20,0x20,0x00,0x88,0x88,0x88,0x88,0x88,0x70,0x00,0x88,0x88,0x88,0x88,0x50, 0x20,0x00,0x88,0x88,0x88,0xa8,0xa8,0x50,0x00,0x88,0x50,0x20,0x20,0x50,0x88,0x00, 0x88,0x50,0x20,0x20,0x20,0x20,0x00,0xf8,0x10,0x20,0x40,0x80,0xf8,0x00,0x60,0x40, 0x40,0x40,0x40,0x60,0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x30,0x10,0x10,0x10, 0x10,0x30,0x00,0x20,0x50,0x88,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8, 0x00,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8}; /************************************************************************** * put_char * * Print char * **************************************************************************/ void put_char(int x ,int y,int […]