This question already has an answer here: What does the C++ standard state the size of int, long type to be? 24 answers Whilst the "why" can be answered with "Because the standard says so", one could make the argument that the standard could be written differently, to guarantee a particular size. However, the purpose of C and C++ is to produce very fast code on all mach
这个问题在这里已经有了答案: C ++标准规定int,long类型的大小是什么? 24个答案 虽然“为什么”可以用“因为标准是这样说”来回答的,人们可以说标准可以写成不同的方式来保证特定的尺寸。 但是,C和C ++的目的是在所有机器上生成非常快速的代码。 如果编译器必须确保int对于该机器来说是一个“不自然的大小”,那就需要额外的指令。 对于几乎所有的情况,这都不是必需的,你所关心的只是它足够“足够我想做”。 所以,为了
Possible Duplicate: size of int, long, etc Is `long` guaranteed to be at least 32 bits? I wanted to find out maximum of each data type for my computer. the code is : int main() { using namespace std; cout << numeric_limits<int>::max() << endl; cout << numeric_limits<long>::max() << endl; cout << numeric_limits<long long>::max
可能重复: int大小,long等等 “长”保证至少有32位? 我想找出我的电脑的每种数据类型的最大值。 代码是: int main() { using namespace std; cout << numeric_limits<int>::max() << endl; cout << numeric_limits<long>::max() << endl; cout << numeric_limits<long long>::max() << endl; return 0; } 打印: 2147483647 2147483647
Possible Duplicate: size of int, long, etc Does the size of an int depend on the compiler and/or processor? I'm not sure if similar questions have been asked before on SO (Atleast, I couldn't find any while searching, so thought of asking myself). What determines the size of int (and other datatypes) in C . I've read it depends on the machine/operating system/compiler, but ha
可能重复: int大小,long等等 int的大小是否取决于编译器和/或处理器? 我不确定在SO之前是否有类似的问题(Atleast,我找不到任何搜索,所以想到问自己)。 什么决定了C中int (和其他数据类型)的大小。 我读过它取决于机器/操作系统/编译器,但还没有遇到任何覆盖另一个的东西的清晰/足够详细的解释等。任何解释或指针都会非常有帮助。 编译器最终会做到这一点,但为了让编译后的代码能够很好地与系统库配合使用
Possible Duplicate: size of int, long, etc Does the size of an int depend on the compiler and/or processor? What decides the sizeof an integer? I'm using a 64-bit machine. $ uname -m x86_64 $ file /usr/bin/file /usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, stripped $ When I ran the following program,
可能重复: int大小,long等等 int的大小是否取决于编译器和/或处理器? 什么决定一个整数的大小? 我使用的是64-bit机器。 $ uname -m x86_64 $ file /usr/bin/file /usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, stripped $ 当我运行下面的程序时,我将sizeof(int)作为4-bytes 。 #include <stdio.h> int main(void)
By my reading of the C++ Standard, I have always understood that the sizes of the integral fundamental types in C++ were as follows: sizeof(char) <= sizeof(short int) <= sizeof(int) <= sizeof(long int) I deduced this from 3.9.1/2: There are four signed integer types: “signed char”, “short int”, “int”, and “long int.” In this list, each type provides at least as much storage as those
通过阅读C ++标准,我一直认识到C ++中积分基本类型的大小如下: sizeof(char) <= sizeof(short int) <= sizeof(int) <= sizeof(long int) 我从3.9.1 / 2推导出来的: 有四个有符号整数类型:“signed char”,“short int”,“int”和“long int”。在此列表中,每种类型至少提供与列表中的前一种类型相同的存储空间。 普通整数具有执行环境架构所建议的自然大小 此外, char的大小被3.9.1 /描述为: 足够大以存储实
When debugging a segfault error in a cross compiled embedded linux environment, I isolated the problem to be a call of memset. Further investigation showed, that there is something strange going on. I tried to run a test application on the target with the following code: string st; st = "teststring"; std::cout << "address: " << &st << std::endl; std::cout << "sizeo
在交叉编译的嵌入式Linux环境中调试segfault错误时,我将问题隔离为memset的调用。 进一步的调查显示,有一些奇怪的事情发生。 我试图用以下代码在目标上运行测试应用程序: string st; st = "teststring"; std::cout << "address: " << &st << std::endl; std::cout << "sizeof: " << sizeof(st) << std::endl; std::cout << "value (before): " << st << std::e
I need to profile some code running C++ on Linux. Can you guys recommend some profilers? Use gprof. Just compile with -pg flag (I think (but am not sure) you have to turn of optimizations though.) and use gprof to analyze the gmon.out file that your executable will then produce. eg: gcc -pg -o whatever whatever.c ./whatever gprof whatever gmon.out Same thing with g++ and cpp. valgrin
我需要分析一些在Linux上运行C ++的代码。 你们可以推荐一些配置文件吗? 使用gprof。 只需用-pg标志进行编译(我认为(但不确定)你必须优化),然后使用gprof分析gmon.out文件,然后执行你的可执行文件。 例如: gcc -pg -o whatever whatever.c ./whatever gprof whatever gmon.out 与g ++和cpp一样的东西。 valgrind是一个知名的linux分析器 从RotateRight(http://www.rotateright.com)放大是我一直在使用的
I see a lot of c++ code that looks like this: for( const_iterator it = list.begin(), const_iterator ite = list.end(); it != ite; ++it) As opposed to the more concise version: for( const_iterator it = list.begin(); it != list.end(); ++it) Will there be any difference in speed between these two conventions? Naively the first will be slightly faster since list.end() is only calle
我看到很多看起来像这样的c ++代码: for( const_iterator it = list.begin(), const_iterator ite = list.end(); it != ite; ++it) 与更简洁的版本相反: for( const_iterator it = list.begin(); it != list.end(); ++it) 这两个公约的速度会有什么不同? 天真的第一个会稍微快一点,因为list.end()只被调用一次。 但是因为迭代器是const的,所以编译器似乎会将这个测试从循环中拉出来,为两者产生等效
So far, I've only used Rational Quantify. I've heard great things about Intel's VTune, but have never tried it! Edit: I'm mostly looking for software that will instrument the code, as I guess that's about the only way to get very fine results. See also: What are some good profilers for native C++ on Windows? For linux development (although some of these tools might wo
到目前为止,我只使用了Rational Quantify。 我听说过关于英特尔VTune的伟大之处,但从未尝试过! 编辑:我主要是在寻找能够测试代码的软件,因为我想这是获得非常好的结果的唯一方法。 也可以看看: Windows上的本机C ++有哪些好的分析器? 对于linux开发(尽管其中一些工具可能在其他平台上工作)。 这些是我所知道的两个大牌,还有很多其他较小的牌在一段时间内没有看到积极的发展。 Valgrind的 TAU - 调整和
This question already has an answer here: How can I profile C++ code running in Linux? 10 answers Measuring execution time of a function in C++ 4 answers There's another way to find the problem(s) than by getting a breakdown of function times. Run it under a debugger, and manually interrupt it several times, and each time examine the call stack. If you look at each level of the call
这个问题在这里已经有了答案: 我如何分析在Linux中运行的C ++代码? 10个答案 在C ++ 4答案中测量函数的执行时间 还有另一种方法来查找问题,而不是通过分解功能时间。 在调试器下运行它,并手动中断它几次,每次检查调用堆栈。 如果您查看代码中的每个级别的调用堆栈,您都可以清楚地知道为什么这个时刻正在花费时间。 假设你有一个速度问题,修复后会节省一些时间,比如30%。 这意味着您检查的每个堆栈样本在问