我对GCC -O3标志非常熟悉,但是它与-Os有何不同,在哪种情况下我们应该优先选择其他?
术语"应用程序足迹"对于用C/C++开发的应用程序意味着什么.以及我们如何计算C/C++应用程序的足迹.
我有一个C/C++应用程序,我需要确定它所依赖的所有(共享)库,所以我可以与其他人共享它和库,这样他们就不必在Linux上安装任何软件包了.
那么可以确定C++应用程序所依赖的所有库吗?
一点点澄清,我暂时没有应用程序makefile,这就是为什么我必须找到另一种方式.
下面的代码用g ++编译好
#include <iostream>
using namespace std;
int main()
{
for (struct { int i; double j; } x = {0,0}; x.i < 10; ++x.i, x.j+=.1)
{
std::cout << x.i << " " << x.j << '\n';
}
}
Run Code Online (Sandbox Code Playgroud)
但是使用MSVC2005我会收到错误
error C2332: 'struct' : missing tag name
error C2143: syntax error : missing ')' before '{'
warning C4094: untagged 'struct' declared no symbols
error C2059: syntax error : 'empty declaration'
error C2143: syntax error : missing ';' before ')'
error …Run Code Online (Sandbox Code Playgroud) 下面的代码显示在函数中创建的对象create()的生命周期延长到const ref创建的生命周期main,这在所有情况下都是正确的吗?我的意思是我们可以通过创建对它的引用来延长某些情况下的临时寿命吗?或者在这种特定情况下,编译器行为不端?
它是用MSVC2005编译的
#include <iostream>
class testClass
{
public:
testClass()
{
std::cout << "in testClass " << ((void*)this) << std::endl;
}
~testClass()
{
std::cout << "in ~testClass " << ((void*)this) << std::endl;
}
};
testClass create()
{
return testClass();
}
int main()
{
{
testClass const& obj = create();
std::cout << "we got a const reference to obj " << ((void*)&obj) << std::endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
产量
in testClass 0018FF13
we …Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用函数指针,面临问题,创建了一个测试用例来显示它...下面的代码失败,MSVC2005上面有以下错误(简单来说我想通过基类函数指针访问dervied类函数)
错误C2440:'=':无法从'void(__ thiscall ClassB ::*)(void)'转换为'ClassAFoo'
class ClassA {
public:
virtual void foo()
{
printf("Foo Parent");
}
};
typedef void (ClassA::*ClassAFoo)();
class ClassB : public ClassA {
public:
virtual void foo()
{
printf("Foo Derived");
}
};
int main() {
ClassAFoo fPtr;
fPtr = &ClassB::foo;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是
ClassB::foo,这段代码编译好了,没有任何进一步的修改,为什么这样,不应该fPtr = &ClassB::foo;再次导致编译时错误?我得到了以下示例代码
// unordered_map::find
#include <iostream>
#include <string>
#include <unordered_map>
int main ()
{
std::unordered_map<std::string,double> mymap = {
{"mom",5.4},
{"dad",6.1},
{"bro",5.9} };
std::string input;
std::cout << "who? ";
getline (std::cin,input);
std::unordered_map<std::string,double>::const_iterator got = mymap.find (input);
if ( got == mymap.end() )
std::cout << "not found";
else
std::cout << got->first << " is " << got->second;
std::cout << std::endl;
return 0;
Run Code Online (Sandbox Code Playgroud)
当我尝试在Windows 7上使用VS 2010编译它时,我得到编译时错误(虽然它看起来不错)
1>\testing.cpp(13): error C2552: 'mymap' : non-aggregates cannot be initialized with initializer list
1> 'std::tr1::unordered_map<_Kty,_Ty>' : Types with a …Run Code Online (Sandbox Code Playgroud) 我有两个几乎相同的循环,但在性能上有显着差异,都在MSVC2010上测试,系统~2.4 GHZ和8GB RAM
下面的循环需要大约2500毫秒才能执行
for (double count = 0; count < ((2.9*4/555+3/9)*109070123123.8); count++)
;
Run Code Online (Sandbox Code Playgroud)
这个循环执行时间不到1毫秒
for (double count = ((2.9*4/555+3/9)*109070123123.8); count >0; --count)
;
Run Code Online (Sandbox Code Playgroud)
这里有什么巨大的变化?一个得到后增量和其他使用预增量可以导致如此巨大的差异?
我有一个UI应用程序,它分别将输出呈现为16,24或32 bpp的屏幕外帧缓冲.
我需要计算音高,我的理解是音高是一条扫描线中的字节数,它是否等于screenx*bitsperpixel?虽然显然它没有产生正确的结果.
我们可以用公式(通用)来计算音高吗?
我有一个简单的脚本(测量CPU开销)
#!/bin/bash
WAIT=2
i=1
while :
do
# Obtain the cpu usage
top -n 1 > t.$i
i=$(($i+1))
sleep $WAIT
done
Run Code Online (Sandbox Code Playgroud)
当我运行它时
./Script.sh
Run Code Online (Sandbox Code Playgroud)
它按预期工作.
但是当我把它作为
./Script.sh&
Run Code Online (Sandbox Code Playgroud)
它什么都不做(文件没有创建).我在这里错过了什么?
c++ ×9
c ×3
linux ×3
g++ ×2
gcc ×2
opengl ×1
opengl-es ×1
optimization ×1
performance ×1
shell ×1
stl ×1
visual-c++ ×1
windows ×1