/ CLR和boost :: bind和boost :: function的代码生成错误 [英] Code gen error with /CLR and boos::bind and boost::function

查看:91
本文介绍了/ CLR和boost :: bind和boost :: function的代码生成错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在托管代码中使用boost :: bind和boost :: function,

但似乎存在一些代码生成问题。以下

代码编译得很好,但是当你用b(b)用函数为空来调用它时,函数对象抛出一个异常。如果你取消评论

#pragma unamanged,它运行正常。在编译函数和绑定为托管时,它似乎是代码生成

问题。


谢谢


Russell


#include" stdafx.h"

#using< mscorlib.dll>


// #pragma unmanaged

#include< boost / bind.hpp>

#include< boost / function.hpp>

class Test_c

{

public:

void test(void)

{

}

};


int main()

{

Test_c测试;

boost :: function< void(void)> f(boost :: bind(& Test_c :: test,& Test));

f();

返回0;

}

解决方案



--------------------

日期:星期一,2004年6月7日10:52:15 +0100
来自:Russell Hind< rh *** @ mac.com>
主题:代码生成错误用/ CLR和boost :: bind和boost :: function

我正在尝试在托管代码中使用boost :: bind和boost :: function,但似乎有一些代码生成问题。以下
代码编译正常,但是当你用f()调用函数为空时,函数对象会抛出异常。如果你取消评论
#pragma unamanged,它运行正常。在编译函数和绑定为托管时,它似乎是代码生成问题。




这听起来很熟悉。

function \ function_base.hpp中应该有一个名为has_empty_target的函数。它返回一个bool;如果你改变它返回

一个int我相信问题应该停止发生。


原因是bool没有被正确编组/>
非托管/托管转换。 vararg函数编译为非托管。

请参阅此链接以获取更多信息:

http://support.microsoft.com/default...b;en-us;813488

-

Arjun Bijanki,Microsoft Visual C ++团队

此帖子提供按现状没有保证,也没有授予任何权利。

使用包含的脚本样本须遵守
http://www.microsoft.com/info/cpyright.htm


Arjun Bijanki [VCPP MSFT]写道:


这听起来很熟悉。
function \ function_base.hpp中应该有一个名为has_empty_target的函数。它返回一个bool;如果你改变它返回
一个int我相信问题应该停止发生。

原因是bool没有在非托管/托管转换中正确编组。 vararg函数编译为不受管理。
请参阅此链接以获取更多信息:

http://support.microsoft.com/default...b;en-us;813488




谢谢,只是出于兴趣,VS.Net 2003会有某种服务包

,页面上会提到修复此问题吗?


Russell


Russell Hind写道:


谢谢,只是出于兴趣,是否会为VS.Net 2003提供某种服务包以及
页面上提到的修复程序?




不是直接回答问题(我不能),但是IIRC,这是实际上是一个CLR错误,而不是C ++错误。


-cd


I''m trying to use boost::bind and boost::function inside managed code,
but there appears to be some code generation problems. The following
code compiles fine, but the function object throws an exception when you
call it with f() saying the function is empty. If you un-comment the
#pragma unamanged, it runs fine. It appears to be a code generation
problem when compiling function and bind as managed.

Thanks

Russell

#include "stdafx.h"
#using <mscorlib.dll>

//#pragma unmanaged

#include <boost/bind.hpp>
#include <boost/function.hpp>

class Test_c
{
public:
void test(void)
{
}
};

int main()
{
Test_c Test;
boost::function<void (void)> f(boost::bind(&Test_c::test, &Test));
f();
return 0;
}

解决方案


--------------------

Date: Mon, 07 Jun 2004 10:52:15 +0100
From: Russell Hind <rh***@mac.com>
Subject: Code gen error with /CLR and boos::bind and boost::function
I''m trying to use boost::bind and boost::function inside managed code,
but there appears to be some code generation problems. The following
code compiles fine, but the function object throws an exception when you
call it with f() saying the function is empty. If you un-comment the
#pragma unamanged, it runs fine. It appears to be a code generation
problem when compiling function and bind as managed.



This sounds familiar. There should be a function named has_empty_target in
function\function_base.hpp. It returns a bool; if you change it to return
an int I believe the problem should stop occurring.

The reason is that the bool is not being properly marshalled across
unmanaged/managed transitions. vararg functions are compiled as unmanaged.
Please see this link for more information:

http://support.microsoft.com/default...b;en-us;813488
--
Arjun Bijanki, Microsoft Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


Arjun Bijanki [VCPP MSFT] wrote:


This sounds familiar. There should be a function named has_empty_target in
function\function_base.hpp. It returns a bool; if you change it to return
an int I believe the problem should stop occurring.

The reason is that the bool is not being properly marshalled across
unmanaged/managed transitions. vararg functions are compiled as unmanaged.
Please see this link for more information:

http://support.microsoft.com/default...b;en-us;813488



Thanks, just out of interest, will there be some sort of service pack
for VS.Net 2003 with the fix for this in that is mentioned on the page?

Russell


Russell Hind wrote:


Thanks, just out of interest, will there be some sort of service pack
for VS.Net 2003 with the fix for this in that is mentioned on the
page?



Not directly answering the question (which I cannot), but IIRC, this is
actually a CLR bug, not a C++ bug.

-cd


这篇关于/ CLR和boost :: bind和boost :: function的代码生成错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆