小编Ant*_*kov的帖子

Cout没有打印号码

问题

我从一个简单的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)

环境

  • 开发机器:
    • OS X 10.6.8
    • 编译器LLVM 1.7
    • Xcode 3.2.6
  • 试验机:
    • OS X 10.6.8

c++ printf pointers cout

16
推荐指数
1
解决办法
1万
查看次数

如何在将1到1000万的整数列表写入文件时获得良好的性能?

我想要一个能编写序列的程序,

1
...
10000000
Run Code Online (Sandbox Code Playgroud)

到一个文件.什么是最简单的代码可以编写,并获得不错的性能?我的直觉是存在一些缺乏缓冲的问题.我的C代码以100 MB/s的速度运行,而通过引用,Linux命令行实用程序dd9 GB/s 3 GB/s的速度运行(对不起,请注意 - 请注意 - 我对大图订单更感兴趣 - 虽然很高).

人们会认为这将是一个现在解决的问题...即任何现代编译器都会立即编写这样的程序,表现得相当好......

C代码

#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次的性能框架可获得相当的性能.

Haskell代码

一个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)

linux performance haskell

7
推荐指数
1
解决办法
496
查看次数

在 LLVM 下的 Makefile 中通过 LDFLAGS 加载 zlib 的正确方法是什么?

我的 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上不同)

c++ makefile ios

5
推荐指数
1
解决办法
3419
查看次数

我如何解析LLVM IR

我有文本格式的LLVM IR代码.我想做的是能够解析它并修改该代码.是否有一个API可以帮助解析LLVM IR代码?我的系统应该有哪些库?在这一刻我已经clang安装了编译器和LLVM,因为我可以使用,如命令llc,optllvm-link.

llvm

4
推荐指数
1
解决办法
2843
查看次数

使用Clang在C中复制符号

我目前正在研究我的第一个"严肃"的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上.有帮助吗?

c duplicate-symbol

2
推荐指数
1
解决办法
1万
查看次数

指针立即变为NULL

我有以下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)

c++

2
推荐指数
1
解决办法
494
查看次数

Apple Mach-O Linker(ld)使用Switch语句时出错?

我正在创建一个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.非常感谢.

macos cocoa mach-o objective-c

1
推荐指数
1
解决办法
4517
查看次数