473,883 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

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;
}
Nov 17 '05 #1
13 3589

--------------------
Date: Mon, 07 Jun 2004 10:52:15 +0100
From: Russell Hind <rh***@mac.co m>
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_targe t in
function\functi on_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

Nov 17 '05 #2
Arjun Bijanki [VCPP MSFT] wrote:

This sounds familiar. There should be a function named has_empty_targe t in
function\functi on_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
Nov 17 '05 #3
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
Nov 17 '05 #4
Yes, this is a fairly deep issue with how the marshalling concepts in the
CLR that could not realistically be fixed in a service pack.

Ronald Laeremans
Visual C++ team

"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:u6******** ******@TK2MSFTN GP11.phx.gbl...
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

Nov 17 '05 #5
Ronald Laeremans [MSFT] wrote:
Yes, this is a fairly deep issue with how the marshalling concepts in the
CLR that could not realistically be fixed in a service pack.


But the support page says they have an update of clxx.dll and feac.dll.
How could these not be distributed as a patch, if you can ring up for
them?

It makes me worried about trying to move to VC++. Currently have lots
of code in C++Bulider and am trying to port it to compare with VC++ but
if using bools can cause errors, its pretty much a waste of time.

Cheers

Russell
Nov 17 '05 #6
Russell Hind wrote:
It makes me worried about trying to move to VC++. Currently have lots
of code in C++Bulider and am trying to port it to compare with VC++
but if using bools can cause errors, its pretty much a waste of time.


Only when bools are marshalled from unmanaged to managed is there a problem.
If you're just moving native C++ from Borland to VC++ you won't have any
problems related to bools.

-cd
Nov 17 '05 #7
I thought this, but the initial code I posted was all compiled as
managed. AFAIK, the boost headers don't put #pragma unmanaged anywhere
and all the function code is template stuff in header files so should
have been compiled as managed. So why would the error occur?

(I have solved the problem by making the has_empty_targe t return an int
for now).

Thanks

Russell

Carl Daniel [VC++ MVP] wrote:
Russell Hind wrote:
It makes me worried about trying to move to VC++. Currently have lots
of code in C++Bulider and am trying to port it to compare with VC++
but if using bools can cause errors, its pretty much a waste of time.

Only when bools are marshalled from unmanaged to managed is there a problem.
If you're just moving native C++ from Borland to VC++ you won't have any
problems related to bools.

-cd

Nov 17 '05 #8
Russell Hind wrote:
I thought this, but the initial code I posted was all compiled as
managed. AFAIK, the boost headers don't put #pragma unmanaged
anywhere and all the function code is template stuff in header files
so should have been compiled as managed. So why would the error
occur?


When you compile C++ as managed with VC7.1 you get a mixture of managed and
unmanaged code as a result. Apparently you were lucky enough to get a bool
marshalled from unmanaged to managed in the process. Whidbey (VC8) will
support generation of pure MSIL from C++ code but the current compiler does
not.

-cd

Nov 17 '05 #9
"Russell Hind" <rh***@mac.co m> wrote in message
news:Oo******** ********@tk2msf tngp13.phx.gbl. ..
(I have solved the problem by making the has_empty_targe t return an int
for now).


That's one way to go. FWIW, When this problem bit me in the ***, I did this:

bool someFunc()
{
bool ok;

// set ok

__asm xor eax, eax
return ok;
}

On the fine day when the problem is resolved, I'll search for the __asm
lines and remove them and keep the same function signatures.

Regards,
Will
Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2091
by: Tron Thomas | last post by:
Given the following code: #include <vector> #include <algorithm> #include <functional> class Value { public: explicit Value(int value) : m_value(value) {}
7
1262
by: Steve V | last post by:
Hi I'm using visual c++ .net 7.1 and so I'm taking advantage of the some of the classes in the boost library, like bind.hpp and function.hpp The problem is that this particular header will occasionally freeze visual studio, causing me to force it to shut down and lose whatever changes I've made :( I can't find anything anywhere on the net that mentions this behaviour so if anyone can suggest anything I'd be very appreciative
8
11012
by: Lars Schouw | last post by:
Guys, Is there anyway in C++ to setup a callback for a member function that takes two arguments I am trying to use boost::function but that only works with std::bind1st that does only take one parameter. My function I want to call back looks like this: struct X { double f_cos(double x , void * p);
3
3468
by: DavidPL | last post by:
Hello, I have some problem with bind method in PDO on Oracle with clob | long column type. I have table named TEST_TABLE where I have two columns: ID (int 10, 0) and TEXT (varchar 4000 or long or clob). When I try execute PHP code (based on example in manual): <?php
2
2638
by: Faheem Mitha | last post by:
Hi, The following bit of code compiles fine with gcc 3.3 or later, but has problems with the Intel C++ compiler version 9.1, which produces the following error message. Is this a compiler bug, or is there something wrong with the code? If the former, I'd be grateful for suggestions of a workaround, and if the latter, please tell me what I'm doing wrong.
1
5567
by: Noah Roberts | last post by:
Trying to use boost::function in a C++/CLI program. Here is code: pragma once #include <boost/function.hpp> #include <boost/shared_ptr.hpp> #include <vector> using namespace System;
4
2496
by: silverburgh.meryl | last post by:
I have code which uses Boost lambda in a template like this: using namespace boost::lambda; template<class T> bool lessThanXY( T& src, T& dest ) { return (src.getY() < dest.getY()); } template<class T1, class T2>
3
6963
by: Kurt Jakobsen | last post by:
Hello, Sorry for putting this problem back on the list. I had it previously under another title that now does not describe the real problem. Hopefully the new title will trigger someone that has had the same problem to respond... The problem: When I want to select page 2 in my grid view control, the grid view disappear. After some trail and error (with good help from others on this network) it seems like the problem appears when the...
3
3350
by: Giovanni Gherdovich | last post by:
Hello, in the following code I have a pointer (to function), say p, of type double (*)(double, double, void*) and I try to fix the second argument of the function *p to a given value (using boost::bind), but the compiler complains, because of a type mismatch in an assignment which I think should be legal:
0
9944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11151
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10752
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9582
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7974
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5996
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3238
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.