我从一个简单的cout没有输出,而printf将始终打印数字:
std::cout << variableuint8; // prints nothing
printf("%u", variableuint8); // prints the number
Run Code Online (Sandbox Code Playgroud)
我以前从未遇到过这种行为,虽然我有一个解决方法,但我想了解它.
耶,指针.所以它可能比所述的更多参与.这是上下文 - 我不认为它应该重要,当cout和printf获取信息时,它被解除引用到一个简单的unsigned char.这可能是解决问题所需的更多信息,但我想完全了解它是否相关.
typedef unsigned char UInt8;
typedef unsigned short UInt16;
typedef struct{
UInt8 len;
// some other definitions. sizeof(DeviceNotification) <= 8
}DeviceNotification;
UInt8 somerandomdata[8];
DeviceNotification * notification;
notification = (DeviceNotification *) somerandomdata;
std::cout << "Len: (" << notification->len << ")\n";
printf("Len: (%u)\n", notification->len);
Run Code Online (Sandbox Code Playgroud)
随机数据在别处初始化.对于此输出,数组中的第一个字节是0x08:
Len: ()
Len: (8)
Run Code Online (Sandbox Code Playgroud)
我想要一个能编写序列的程序,
1
...
10000000
Run Code Online (Sandbox Code Playgroud)
到一个文件.什么是最简单的代码可以编写,并获得不错的性能?我的直觉是存在一些缺乏缓冲的问题.我的C代码以100 MB/s的速度运行,而通过引用,Linux命令行实用程序dd
以9 GB/s 3 GB/s的速度运行(对不起,请注意 - 请注意 - 我对大图订单更感兴趣 - 虽然很高).
人们会认为这将是一个现在解决的问题...即任何现代编译器都会立即编写这样的程序,表现得相当好......
#include <stdio.h>
int main(int argc, char **argv) {
int len = 10000000;
for (int a = 1; a <= len; a++) {
printf ("%d\n", a);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我正在编译clang -O3
.调用putchar('\n')
8次的性能框架可获得相当的性能.
一个naiive Haskell实现以13 MiB/sec的速度运行,并使用ghc -O2 -optc-O3 -optc-ffast-math -fllvm -fforce-recomp -funbox-strict-fields
.(我没有重新编译我的库-fllvm
,也许我需要这样做.)代码:
import Control.Monad
main = forM [1..10000000 :: Int] …
Run Code Online (Sandbox Code Playgroud) 我的 CFLAGS 有
-I../../usr/local/sys/usr/include
Run Code Online (Sandbox Code Playgroud)
正确加载 zlib.h
LDFLAGS 是
LDFLAGS = -L../../usr/local/sys/usr/lib -lxml2 -lzlib
Run Code Online (Sandbox Code Playgroud)
但是当链接器尝试链接时会发生以下情况
1> + Linking project files...
1> ld: library not found for -lzlib
1> collect2: ld returned 1 exit status
1> make: *** [link] Error 1
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?
windows7下环境是iosdevenv(所以目录结构与mac os上不同)
我有文本格式的LLVM IR代码.我想做的是能够解析它并修改该代码.是否有一个API可以帮助解析LLVM IR代码?我的系统应该有哪些库?在这一刻我已经clang
安装了编译器和LLVM,因为我可以使用,如命令llc
,opt
和llvm-link
.
我目前正在研究我的第一个"严肃"的C项目,一个16位的虚拟机.当我将文件从一个大的源文件拆分成多个源文件时,链接器(无论是通过clang,gcc,cc还是ld调用)都会发出错误:
ld: duplicate symbol _registers in register.o and main.o for inferred
architecture x86_64
Run Code Online (Sandbox Code Playgroud)
registers
主文件中没有任何声明.uint16_t
如果有帮助,它是一个数组.我使用内置编译器(不是GNU gcc)在Mac OS 10.7.3上.有帮助吗?
我有以下LLVM代码.奇怪的是,在if块之外的新指令分配后si
,类型的变量StoreInst
立即变为null(0),而我已在外部范围声明它.这里发生了什么?
Value *OldVal = NULL;
StoreInst* si = NULL;
if ( ... )
{
if ( ... )
{
....
if ( ... )
{
...
StoreInst* si = new StoreInst(...);
errs() << "si = " << si << "\n"; // Get some address here
}
errs() << "-->SI = " << si << "\n"; // Here I get NULL, why?
}
...
}
Run Code Online (Sandbox Code Playgroud)
我得到这样的输出,
si = 0x1822ba0
-->SI = 0x0
Run Code Online (Sandbox Code Playgroud) 我正在创建一个Objective-C程序,在调用C函数时,它会尝试转换一个数字并返回一个字符串.但是,当我尝试编译时,这会导致Apple Mach-O链接器(ld)错误.
这是代码片段:
NSString * convertNum (int theNum) {
NSString *numString;
switch (theNum) {
case 102:
numString = @"Oh yea, string 102";
break;
case 104:
numString = @"Oh great, string 104";
break;
/* ... */
default:
numString = @"Don't feed me with something I don't know!";
break;
}
return numString;
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么吗?我正在使用Xcode 4.非常感谢.