小编Ped*_*ino的帖子

在Mac OS X上的-fno-rtti共享库中多态捕获异常

我正在建立一个共享库f-no-rtti.在内部,此库会抛出std:invalid_argument并捕获std::exception,但从catch不输入该子句.

以下代码重现了该问题(g ++ 4.2,Mac OS X 10.6):

// library.cpp: exports f(), compiled with -fno-rtti
#include <stdexcept>
#include <iostream>
extern "C" {
    void f() {
        try {
            throw std::invalid_argument("std::exception handler");
        } catch( std::exception& e) {
            std::cout << e.what() << "\n";
        } catch(...) {
            std::cout << "... handler\n";
        }
    }
}
Run Code Online (Sandbox Code Playgroud)
// main.cpp: the main executable, dynamically loads the library
#include <dlfcn.h>
typedef void(*fPtr)();

int main() {
    void* handle = dlopen( "./libexception_problem.dylib", RTLD_LAZY ); …
Run Code Online (Sandbox Code Playgroud)

c++ macos gcc shared-libraries rtti

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

std :: stringstream如何在operator <<中处理wchar_t*?

鉴于以下代码段无法编译:

std::stringstream ss;
ss << std::wstring(L"abc");
Run Code Online (Sandbox Code Playgroud)

我不认为这个会:

std::stringstream ss;
ss << L"abc";
Run Code Online (Sandbox Code Playgroud)

但它确实(至少在VC++上).我猜这是由于以下ostream::operator<<过载:

ostream& operator<< (const void* val );
Run Code Online (Sandbox Code Playgroud)

如果我无意中混合了字符类型,这是否有可能默默地破坏我的代码?

c++ unicode stl stringstream

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

如何找出我的DLL增长如此之多的原因

我一直在努力的DLL最近增长了很多.是否有任何工具可以告诉我对此负责的是什么?例如,它是一个被实例化太多次的模板,或者可能是第三方库,或者可能是提升?

我正在寻找一种看大小而不是性能的分析器.

c++ optimization profiler

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

在持有boost :: interprocess :: scoped_lock时睡眠会导致它永远不会被释放

我做IPC Linux的使用boost::interprocess::shared_memory_object按照基准(匿名互斥体示例).

有一个服务器进程,它创建shared_memory_object并写入它,同时保持interprocess_mutex包裹在scoped_lock; 和客户端进程打印其他人写的任何内容 - 在这种情况下,它是一个int.

我遇到了一个问题:如果服务器在持有互斥锁的情况下休眠,则客户端进程永远无法获取它并永远等待.

越野车服务器循环:

using namespace boost::interprocess;
int n = 0;
while (1) {
    std::cerr << "acquiring mutex... ";
    {
        // "data" is a struct on the shared mem. and contains a mutex and an int
        scoped_lock<interprocess_mutex> lock(data->mutex);
        data->a = n++;
        std::cerr << n << std::endl;
        sleep(1);
    } // if this bracket is placed before "sleep", everything works
}
Run Code Online (Sandbox Code Playgroud)

服务器输出: …

c++ linux mutex ipc boost-interprocess

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

使用strcat时访问冲突写入位置错误

我在C++中使用strcat函数时遇到问题.

如果我做 :

MyClass::MyClass(char* myString){

char* AnotherString = myString;
strcat(AnotherString, "bob");

}
Run Code Online (Sandbox Code Playgroud)

一切都很好.但是,如果我这样做:

MyClass::MyFunction(){

char* AnotherString = "fred";
strcat(AnotherString, "bob");

}
Run Code Online (Sandbox Code Playgroud)

我在strcat.asm中得到一个未处理的异常.有任何想法吗?

问候

c c++

0
推荐指数
2
解决办法
3911
查看次数