Tag: clang

在C或C ++链接器中是否有任何类型检查?

我正确地说连接器没有进行function参数检查。 它们不检查函数调用的数量或类型,也不检查全局数据引用的类型。 这对所有连接体都是如此吗? 我在x86-64上使用Clang定位Linux。 链接器是否检查引用是否在正确的段中? 或者就链接器而言,外部引用实际上只是一个void *? 我来自高级语言背景C#和Scala,所以对于那些沉浸在低级别世界中的人来说,这似乎是显而易见的。 我在汇编程序中写了几个函数(系统调用),我注意到汇编程序中没有外部函数的参数原型。 上下文:我实际上是在编写一个编译器。 目前我的目标是使用汇编程序函数进行系统调用的预处理C .i文件,但替代方案是C ++,汇编程序甚至机器代码,所以我试图权衡成本和收益,特别是类型检查,汇编器/编译器/ 链接器我可以用来检查我自己的程序及其函数原型生成的正确性。

哪个C99编译器(Clang vs. GCC)更接近const结构域的标准?

我有这样的代码: $ cat test.c #include typedef struct { const int x; } SX; static SX mksx(void) { return (SX) { .x = 10 }; } void fn(void) { SX sx; while((sx = mksx()).x != 20) { printf(“stupid code!”); } } 关于其正确性的2条意见: $ for i in gcc clang; do echo “$i SAYS:”; $i -c -std=c99 -pedantic […]

错误:使用未声明的标识符’errno_t’

这是我死的简单虚拟代码: #include int main(void) { errno_t e; return 0; } 这令人惊讶地引发了这个错误: main.c:5:5: error: use of undeclared identifier ‘errno_t’ errno_t x; ^ 我开始遵循这些跟踪 :当编译器看到包含时,它将首先查看/usr/include当然我找到了errno.h文件。 实际上它除了许可证注释外还有一行,它是: #include 现在,在errno.h /usr/include/sys中,我找到了以下行: #include #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 #include #endif 在/usr/include/_types中的/usr/include/_types _errno_t.h我发现了这个: typedef int errno_t; 所以看起来,它就在那里,它是整数类型的别名,也是errno.h一部分 – 正如它应该的那样。 那为什么不包括在内呢? 为什么编译器会引发未声明的标识符错误? 提前致谢! 相关信息: Compiler: Apple LLVM version 5.1 (clang-503.0.40) (based […]

clang / clang ++在Windows中找不到C / C ++头文件?

1小时前我从http://llvm.org/pre-releases/3.6.0/下载了llvm-3.6.0-rc4-win32.exe。 我试图编译只打印“hello”的简单C代码,但它没有编译,因为clang.exe找不到stdio.h。 当我使用clang-cl.exe和相同的代码时,它工作。 我对clang ++也有同样的问题,即使使用iostream,我在GCC(4.9.1)C ++标题中添加了-I标志,结果如下: C:\Users\One\Desktop>clang++ -I c:\MinGW\x86_64-w64-mingw32\include\c++ main.cpp -lib=libstdc++ In file included from main.cpp:1: c:\MinGW\x86_64-w64-mingw32\include\c++\iostream:38:10: fatal error:’bits/c++config.h’ file not found #include 1 error generated. 有人知道怎么修这个东西吗 ? 编辑:我在MinGW文件夹中找到bits / c ++ config.h我将它添加到-I标志和其他。 我导致链接错误: C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/ bin/ld.exe: cannot find -lib=libstdc++ C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/ bin/ld.exe: skipping incompatible C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/4.9 .1//libstdc++.dll.a when searching for -lstdc++ C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/ bin/ld.exe: skipping incompatible C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/4.9 .1//libstdc++.a […]

为什么C不允许从char **到const char * const *(和C ++)的隐式转换?

我知道从char **到const char **隐式转换无法完成,为什么,以及转换为char *const *工作原理。 请参阅底部以获取有关该说明的链接。 除了一件特别的事情,这一切都是有道理的。 所以我有以下代码: #include void print(const char *const*param) { printf(“%s\n”, param[0]); } int main(int argc, char **argv) { print(argv); return 0; } 如果我将其编译为C ++代码,它编译得非常好。 但是,如果相同的代码只编译为C代码,我会收到一个错误(好吧,警告,但我们假设 – -Werror , -Werror警告视为错误)。 GCC: test.c: In function ‘main’: test.c:12:11: warning: passing argument 1 of ‘print’ from incompatible pointer type [-Wincompatible-pointer-types] print(argv); ^ test.c:4:1: […]

为MacOSX构建,但链接针对iOS模拟器文件构建的dylib

我刚刚使用2013年4月15日的命令行工具升级到Xcode 5 beta,并在标准CMakeTestCCompiler.cmake尝试编译简单测试程序期间运行cmake构建时发出以下警告: cmake -version cmake version 2.8.11.2 ld: building for MacOSX, but linking against dylib built for iOS Simulator file ‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/lib/libSystem.dylib’ for architecture i386 lipo -info /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/lib/libSystem.dylib Non-fat file: libSystem.dylib is architecture: i386 编译步骤是: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -o /Users/temp/testCCompiler.co -c /Users/temp/testCCompiler.c lipo -info /Users/temp/testCCompiler.co Non-fat file: testCCompiler.co is architecture: i386 链接步骤是: /usr/local/bin/cmake […]

有没有办法让gcc或clang警告显式演员表?

我想要做的是找到所有显式的强制转换,从double类型或float到我拥有的一些源文件中的任何其他类型。 有没有内置的gcc方法来做到这一点? 语言是C.谢谢!

如何从内联asm访问C结构/变量?

请考虑以下代码: int bn_div(bn_t *bn1, bn_t *bn2, bn_t *bnr) { uint32 q, m; /* Division Result */ uint32 i; /* Loop Counter */ uint32 j; /* Loop Counter */ /* Check Input */ if (bn1 == NULL) return(EFAULT); if (bn1->dat == NULL) return(EFAULT); if (bn2 == NULL) return(EFAULT); if (bn2->dat == NULL) return(EFAULT); if (bnr == […]

Mac OS X的静态库链接问题:找不到架构x86_64的符号

我正在尝试生成一个静态库并将其与执行二进制文件链接。 这是一个库函数: #include int hello() { return 10; } 使用这些命令,我​​可以得到一个静态库。 gcc -c io.c ar -crv libio.a io.o 使用lip -info ,我检查它是x86_64架构。 ar> lipo -info libio.a input file libio.a is not a fat file Non-fat file: libio.a is architecture: x86_64 这是使用库的主要function。 #include extern int hello(); int main(int argc, char *argv[]) { printf(“%d”, hello()); } 但是,当我将对象与静态库链接时,我有错误。 gcc main.c […]

LTO for gcc或clang可以跨C和C ++方法进行优化

如果链接时优化(LTO)与gcc或clang一起使用 ,是否可以跨C和C ++语言边界优化代码? 例如,C函数可以内联到C ++调用者中吗?