Tag: gcc

GCC的已知C / C ++优化是什么?

我有很多代码需要优化并使其运行得更快。 我用opreport告诉我代码花了很多时间。 我使用以下命令来获取统计信息 opreport -g -l -d 使用不同的标志可以获得建议以获得更好的统计数据,也许每个行号而不是function号找到它。 因此,我所看到的许多问题都与以下方面有关: 指针,多维数组 乘法 循环 我希望编译器能够更好地优化代码,从而帮助他。 我将一些代码块分解为带有字限制的函数,告诉编译器我的指针数组不重叠。 所以我正在寻找(a)可以使代码运行更长时间的常见C结构和(b)如何帮助编译器优化代码。 谢谢

C多行宏问题:为什么不在多行宏定义中使用if(1){…}而不是do {…} while(0)

我想调用循环中的多行宏来打破/继续它。 如果我在多行宏定义中使用“do {…} while(0)”,则break / continue仅对“do {…} while(0)”有效,而不是调用此宏的循环。 所以我考虑在多宏定义中使用“if(1){…}”。 #define EXIT_CIRCULATION() \ if(1){ \ break; \ } void func(){ while(1){ … EXIT_CIRCULATION(); … } } 但我怀疑在宏定义中使用“if(1){…}”是一种好方法,因为我在互联网上找不到任何例子。 谢谢!

在Windows上使用gcc 5.3.0编译Lua 5.2.4模块

我需要使用gcc 5.3.0编译Lua 5.2.4模块。 在Windows上。 在此之前,我按以下步骤构建Lua 5.2.4: gcc -c -DLUA_BUILD_AS_DLL *.c ren lua.o lua.obj ren luac.o luac.obj ar rcs lua524-static.lib *.o gcc -shared -o lua524.dll -Wl,–out-implib,lua524.lib *.o gcc lua.obj lua524.lib -o lua524.exe gcc luac.obj lua524-static.lib -o luac524.exe del *.o *.obj 我想创建的动态库(.dll)写在下面(让我们称之为LuaMath: #include #include #include “lauxlib.h” #include “lua.h” static int IdentityMatrix(lua_State *L) { int in = lua_gettop(L); […]

使用libavcodec,C解码H264video

我正在尝试使用ffmpeg / libavcodec解码原始h264文件,但无法使其正常工作。 输出应该是现在的原始YUV文件。 可以使用GCC编译代码 gcc -o decoder decoder.c -L./lib/ -llibavcodec -llibavutil avcodec.dll,avutil.dll和swresample.dll必须放在.exe开始的目录中。 CMD中的输出看起来像这样(只是它的一部分,但它总是这样): [h264 @ 00a80f20] reference picture missing during reorder [h264 @ 00a80f20] Missing reference picture, default is 65562 [h264 @ 00a80f20] error while decoding MB 80 54, bytestream -10 [h264 @ 00a80f20] concealing 1649 DC, 1649 AC, 1649 MV errors in B […]

我如何正确链接libssh?

我正试图在我的代码中包含一个lib(libssh),但没有任何作用……此时我不确定该怎么做,因为搜索引擎中没有结果出现我正在接收的错误。 我在这里下载了libssh: https : //github.com/substack/libssh 我安装了这些: yum install cmake zlib-devel libpng-devel openssl-devel -y; 创建了一个“build”目录作为libssh的父目录,移动到那里,键入: cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug .. make [root@ build]# cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug LD_DEBUG=all .. — Could NOT find NaCl (missing: NACL_LIBRARIES NACL_INCLUDE_DIRS) — ******************************************** — ********** libssh build options : ********** — zlib support: ON — libgcrypt support: OFF — libnacl support: OFF […]

C表示循环分段故障

当我尝试在gcc上编译此代码时,我收到了分段错误错误。 #include #include #define N_TIMES 600000 #define ARRAY_SIZE 10000 int main (void) { double *array = calloc(ARRAY_SIZE, sizeof(double)); double sum = 0; int i; double sum1 = 0; for (i = 0; i < N_TIMES; i++) { int j; for (j = 0; j < ARRAY_SIZE; j += 20) { sum += array[j] + array[j+1] […]

如何减少ELF部分填充?

我使用crosstool-NG创建了一个带有gcc 6.3.0和glibc 2.25的PowerPC工具链。 我有以下测试程序test.c: int main() { return 0; } 我用命令编译它: powerpc-unknown-linux-gnu-gcc -s -Os -o test test.c 最后的二进制文件是66904字节,比预期的要大得多。 节标题如下所示: $ powerpc-unknown-linux-gnu-readelf -S test There are 27 section headers, starting at offset 0x10120: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 […]

pow函数和long int导致问题

我试图恭维RSA加密方案。 它是这样的: encrypted data = ((message)^e) % n和decrypted data = ((encrypted data)^d) % n 我试图在c中实现这一点。 这是代码: #include #include #include int main(){ long int num = 3255859; long int encrypt =(int)pow((double) num,3) % 33; printf(“%ld\n”,encrypt); return 0; } 我使用gcc -Werror -g -o encrypt encrypt.c -lm编译了这个 这是我得到的输出= -2 ,这显然是错误的。 当我尝试使用较小数字的代码时,我得到了正确的结果。 例如: 当我设置num = 2 ,我得到的结果是8 我知道我要么输入错误,要么我在某个地方跑出界限。 我确实需要使用此代码来加密像上面代码中的大数字一样的大数字。 […]

main.c中定义的宏在另一个包含的文件中不可见

我有多个C和H文件 在main.c我定义了一个宏,在ws_driver.c我想使用它。 ws_driver.h包含在main.c 。 main.c中 #define WS_PORT PORT_D8 #define WS_BIT D8 #define WS_DDR DDR_D8 #include “ws_driver.h” 在ws_dirver.c我有两个检查: ws_driver.c #include “ws_driver.h” #ifndef WS_PORT # error “WS_PORT not defined!” #endif #ifndef WS_BIT # error “WS_BIT not defined!” #endif 两者都失败了。 $ avr-gcc -std=gnu99 -mmcu=atmega328p -DF_CPU=16000000UL -Os -I. -I -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wno-main -Wno-strict-prototypes -Wno-comment -g2 […]

C程序在不同的编译器上给出不同的输出

我运行了一个C程序,并在不同的C编译器上获得了不同的输出。 以下是我的计划 void main() { int i=5; printf(“%d%d%d%d%d”,i++,i–,++i,–i,i); } ON boarnland c ++ complier o / p是 45545 并在gcc上 45555 是真的依赖编译器还是依赖于操作系统? 函数调用中的参数从左到右被压入堆栈。 评估是从堆栈弹出。 并且评估是从右到左,因此结果。