我正在使用一种int类型来存储一个值.根据程序的语义,值总是在很小的范围内变化(0 - 36),并且仅使用int(不是a char)因为CPU效率.
似乎可以在如此小的整数范围内执行许多特殊的算术优化.可以将对这些整数的许多函数调用优化为一小组"神奇"操作,并且甚至可以将某些函数优化为表查找.
那么,是否有可能告诉编译器这int总是在那么小的范围内,并且编译器是否可以进行这些优化?
我试图将指向派生类的数据成员的指针强制转换为指向基类的数据成员的指针,但以下代码无法编译:
class Base
{
public:
virtual void f() {}
};
class Derived : public Base
{
public:
void f() override {}
};
class Enclosing
{
public:
Derived member;
};
int main()
{
Derived Enclosing::*p = &Enclosing::member;
auto bp = static_cast<Base Enclosing::*>(p); // compile error
}
Run Code Online (Sandbox Code Playgroud)
所以我reinterpret_cast改为使用,代码编译:
auto bp = reinterpret_cast<Base Enclosing::*>(p); // passes compile
Run Code Online (Sandbox Code Playgroud)
我试着bp直截了当地使用:
Enclosing instance;
(instance.*bp).f(); // calls Base::f
Run Code Online (Sandbox Code Playgroud)
这不是我的预期,因为成员in Enclosing实际上是Derived类型.然后我尝试了这个:
(&(instance.*bp))->f(); // calls Derived::f
Run Code Online (Sandbox Code Playgroud)
它适用于我的环境,但这种行为有保证吗?
我正在尝试将Google Breakpad集成到Windows Qt项目中.
当我使用MinGW(而不是w64)编译它时,Breakpad按预期工作并在应用程序崩溃时生成Minidump文件.
但是,当我使用MinGW-w64编译相同的代码时,应用程序只是在没有Minidump文件的情况下崩溃.
这个问题可以通过一个简单的测试程序重现:
#include "breakpad/client/windows/handler/exception_handler.h"
#include "breakpad/client/windows/sender/crash_report_sender.h"
void test()
{
// install the exception handler
std::wstring prod(L"some prod");
std::wstring ver(L"some ver");
std::wstring subver(L"some subver");
static google_breakpad::CustomInfoEntry custom_entries[] = {
google_breakpad::CustomInfoEntry(L"prod", prod.c_str()),
google_breakpad::CustomInfoEntry(L"ver", ver.c_str()),
google_breakpad::CustomInfoEntry(L"subver", subver.c_str()),
};
static google_breakpad::CustomClientInfo custom_info = {custom_entries, 3};
std::wstring path(L"some/path/to/dump/file");
auto handler = new google_breakpad::ExceptionHandler(path, nullptr, nullptr, nullptr, google_breakpad::ExceptionHandler::HANDLER_ALL, MiniDumpNormal, (const wchar_t *)nullptr, &custom_info);
// feed crash
*(int*)0x1 = 1;
}
int main()
{
test();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
代码与Breakpad源代码树(不是二进制库)一起编译
似乎没有调用异常处理程序.如果我将其注册到ctor,则不会调用回调函数google_breakpad::ExceptionHandler.
那为什么会这样呢?是否可以将Breakpad集成到MinGW-W64编译的项目中?
我想设置OpenSSL库.为我的Qt项目.在Linux下,内置的OpenSSL工作正常.我把它添加到我的.pro文件中:
LIBS+=-lcrypto
PKGCONFIG += openssl
Run Code Online (Sandbox Code Playgroud)
但如果我在Android中使用它,则会出错.我按照这个说明操作:
$ . ./setenv-android.sh
$ cd openssl-1.0.1h/
$ perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
$ ./config shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir=/usr/local/ssl/$ANDROID_API
$ make depend
$ ./Configure shared android-armv7
$ make build_libs
$ export CC=/home/laci/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
$ export AR=/home/laci/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
$ export ANDROID_DEV=/home/laci/android-ndk-r10/platforms/android-14/arch-arm/usr/
$ make all
$ sudo -E make install CC=$ANDROID_TOOLCHAIN/arm-linux-androideabi-gcc RANLIB=$ANDROID_TOOLCHAIN/arm-linux-androideabi-ranlib
Run Code Online (Sandbox Code Playgroud)
这些网站是我的来源:
我究竟做错了什么?
提前感谢您的回答