Tag: gcc

struct intitialization表示法不使用堆分配存储

使用gcc(GCC)4.4.6,我尝试编译这个程序 – 1 #include 2 #include 3 4 int main(int argc, char *argv[]) 5 { 6 7 struct B { 8 int i; 9 char ch; 10 }; 11 12 struct B *ptr; 13 14 ptr = (struct B*) calloc(1, sizeof(struct B)); 15 16 *ptr = { 17 .i = 10, 18 .ch = ‘c’, […]

签名比无符号整数更快

可能重复: 无符号vs有符号整数的性能 我已经读过某个地方,在x86_64用比较无signed ints的C/C++中的有unsigned ints来比较快,例如for (int i… )比for (uint i…) “更快”。 真的吗? 为什么这是真的? 我知道差异很小,但无论如何。

使用GCC和OMP在C中的特定线程顺序

我需要组建4个团队,每个团队有4个线程,每个团队都有连续的处理器。 我期待的结果是,例如: Team 0 Thread 0 Processor: 0 Team 0 Thread 1 Processor: 1 Team 0 Thread 2 Processor: 2 Team 0 Thread 3 Processor: 3 Team 1 Thread 0 Processor: 4 Team 1 Thread 1 Processor: 5 Team 1 Thread 2 Processor: 6 Team 1 Thread 3 Processor: 7 Team 2 Thread 0 Processor: […]

Eclipse – 在printf()调用之后将fflush(stdout)设置为默认值

有同样的情况 。 是否有任何解决方案,使得fflush(stdout)将在printf()之后自动发生,而不是在每次printf()调用后添加fflush(stdout) ? 我在windows 7上使用Eclipse IDE for C/C++ Developers和gcc –version gcc (GCC) 4.8.1

“选项已启用”和“已通过选项”usind gcc -Q -v之间有什么区别

我正在寻找编译期间使用的默认编译器标志。 因此我使用命令gcc -Q -v 感兴趣的输出如下所示: GNU C(Ubuntu 4.8.4-2ubuntu1~14.04.3)版本4.8.4(x86_64-linux-gnu)由GNU C版本4.8.4编译,GMP版本5.1.3,MPFR版本3.1.2-p3,MPC版本1.0.1 GGC启发式: – param ggc-min-expand = 100 –param ggc-min-heapsize = 131072 传递的选项:-v -imultiarch x86_64-linux-gnu example.c -mtune = generic -march = x86-64 -fstack-protector -Wformat -Wformat-security 启用选项:-faggressive-loop-optimizations -fasynchronous-unwind-tables -fauto-inc-dec -fbranch-count-reg -fcommon -fdelete-null-pointer-checks -fdwarf2-cfi-asm -fearly-inlining -feiminate- unused-debug-types -ffunction-cse -fgcse-lm -fgnu-runtime -fgnu-unique -fident -finline-atomics -fira-hoist-pressure -fira-share-save-slots -fira-share-spill-slots – fivopts -fkeep-static-consts -fleading-underscore […]

在MPI中,多进程scanf只接受一次输入并将垃圾值分配给其他?

我正在尝试使用scanf编写MPI代码,它将单独为所有进程输入输入,但只有一个进程从用户获取输入,而其他进程将垃圾值分配给该变量。 该计划如下 #include #include #include “mpi.h” #include int main(int argc, char* argv[]) { int i, size, rank; int arr; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); printf(“Enter the number\n”); scanf(“%d”,&i); printf(“%d\n”,i); MPI_Finalize(); exit(0); }

使用gcc内联C代码中的所有函数

我有很多没有递归的C程序。 我想让程序没有用户定义的function,但主要function。 GCC可以进行内联但是处于IR级别,所以我无法获得C代码。 资源: int calc(int a , int b) { a=a+b-2; return a ; } int main() { int x=4,y=7; x=calc(x,y); return 0 ; } 目标: int main() { int x=4,y=7; int calc_A=x,calc_B=y; calc_A=calc_A+calc_B-2; x=calc_A; return 0 ; }

程序完成后的分段错误

我正在做一个家庭作业,我对C比较新。我必须为一个整数数组创建一个初始化器。 我教授给我的声明是: typedef int set_t; // Can’t be altered … void init(set_t *thing, int N) {} // Can’t be altered … int main() { set_t a; // Can’t be altered init(&a, 10); // Can’t be altered return 0; } 初始化器应该在数组set_t a;为N个元素分配空间set_t a; 这是我的初始化程序的代码: void init(set_t *thing, int N) { *thing = *(set_t *)malloc(sizeof(set_t)*N); for (int […]

使用-falign-loops选项时这是一个GCC错误吗?

我正在使用此选项来优化嵌入式架构中的for循环( 此处 )。 但是,我注意到当对齐需要添加多个nop指令时,编译器会生成一个nop后跟as-many-as-required零( 0000 )。 我怀疑它是我们编译器中的一个错误,但有人可以确认它不是GCC中的错误吗? 这是一段代码: __asm__ volatile(“nop”); __asm__ volatile(“nop”); for (j0=0; j0<N; j0+=4) { c[j0+ 0] = a[j0+ 0] + b[j0+ 0]; c[j0+ 1] = a[j0+ 1] + b[j0+ 1]; c[j0+ 2] = a[j0+ 2] + b[j0+ 2]; c[j0+ 3] = a[j0+ 3] + b[j0+ 3]; } 使用-falign-loops=8 (或与您的体系结构相关的任何数量,超过所需的最小比对)进行编译。 您可以根据需要添加或删除__asm__行以生成未对齐的循环体。

使用带有未命名嵌套数据类型的指定初始值设定项

我想知道是否有可能在未命名的结构数据成员中使用指定的初始化器…(Yikes,一口,但是,是的,这是我做的事情最干净的方式……)。 如果我有: typedef struct MainStruct { union { uint8_t a8[16]; uint64_t a64[2]; }; uint64_t i64; } MainStruct_t; typedef struct OtherStruct { MainStruct_t main; int otherval; } OtherStruct_t; OtherStruct_t instance = { .main.a64 = { 0, 0 }, .otherval = 3 }; 我尝试编译,我得到错误: tst3.c:16: error: unknown field ‘a64’ specified in initializer 我也尝试过使用.main..a64 ,但我遇到了其他问题。 这是使用gcc 4.4。 不幸的是, […]