473,569 Members | 2,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ISO C++ forbids casting between pointer-to-function and pointer-to-object

ken


I am getting this error from a gcc compile and I was wondering whether
this was 100% valid. This seems a little extreme to me the c++ cast
operators appear to only work on objects which defeats the purpose of
them. I had to remove the C++ cast and change to a C one in order for
gcc to accept it, we are using permissive and I am getting rid of it. Is
this truly correct?

const ::rtl::OUString sFactoryCreatio nFunc =
::rtl::OUString ::createFromAsc ii("createDataA ccessToolsFacto ry");>

- getDbToolsClien tFactoryFunctio n() = reinterpret_cas t<createDataAcc essToolsFactory Function>(>

+ // reinterpret_cas t<createDataAcc essToolsFactory Function> removed for gcc permissive >
+ getDbToolsClien tFactoryFunctio n() = (createDataAcce ssToolsFactoryF unction)(>

osl_getSymbol(g etDbToolsClient Module(), sFactoryCreatio nFunc.pData));

Any comments or better solutions appreciated.

KenF
Jul 19 '05 #1
3 9779


ken wrote:

I am getting this error from a gcc compile and I was wondering whether
this was 100% valid. This seems a little extreme to me


read the error message again.

casting between pointer-to-function and pointer-to-object

What good is it to cast a pointer-to-object to a pointer-to-function?
The later points at executable code, while the first points at data.
So why on earth would one want to cast one into another except for
beeing able to get at the opcodes of a function which, unless you are
writting a disassembler or a debugger, is a rather unusual
thing to do. You don't seem to be doing this, so the error message
points more in the direction of: "Hey buddy, there seems to be something
wrong with your pointer types. Check them!"
--
Karl Heinz Buchegger
kb******@gascad .at
Jul 19 '05 #2
ken
On Fri, 07 Nov 2003 14:38:42 +0100, Karl Heinz Buchegger wrote:
casting between pointer-to-function and pointer-to-object

What good is it to cast a pointer-to-object to a pointer-to-function?
The later points at executable code, while the first points at data.
So why on earth would one want to cast one into another except for
being able to get at the opcodes of a function which, unless you are
writing a disassembler or a debugger, is a rather unusual
thing to do. You don't seem to be doing this, so the error message
points more in the direction of: "Hey buddy, there seems to be something
wrong with your pointer types. Check them!"


The code is casting the function to a void to allow the external interface
to be transparent to the user of that interface. I cannot "undesign" the
interface easily like most projects I have to live with it. There is now
a project to clean this up but that is strategic rather than immediate.

There is no object in void and no object in a function call. Poor design
aside I think that there might be a problem with this message.

KenF
Jul 19 '05 #3
Karl Heinz Buchegger wrote:


ken wrote:

I am getting this error from a gcc compile and I was wondering
whether
this was 100% valid. This seems a little extreme to me


read the error message again.

casting between pointer-to-function and pointer-to-object

What good is it to cast a pointer-to-object to a pointer-to-function?
The later points at executable code, while the first points at data.
So why on earth would one want to cast one into another except for
beeing able to get at the opcodes of a function which, unless you are
writting a disassembler or a debugger, is a rather unusual
thing to do.


A void* is unfortunately also seen as pointer-to-object. Some quite
common interfaces for loading libraries dynamically provide a function
to which you can provide a symbol name as char array, and you get back
a void* that points to it. If it's a function, you have to convert a
void* (i.e. an object pointer) into a function pointer.

Jul 19 '05 #4

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

Similar topics

5
8247
by: Suzanne Vogel | last post by:
** Isn't the 'static_cast' operator the same as traditional type casting? ie, Aren't the following ways of getting b1, b2 the same? // 'Derived' is derived from 'Base' Derived* d = new Derived(); Base* b1 = static_cast<Base*>(d); Base* b2 = (Base*)d; // traditional type casting Such is my understanding from code samples, my own uses, and...
4
3096
by: coeng | last post by:
I am having trouble comprehending the use of the four casting operators in C++. Does anyone know of a URL that provides a very detailed, yet very simple, explanation of what they accomplish and most importantly when you would and when you would not use them (citing examples).
1
9130
by: JohnK | last post by:
under the covers is type casting in VB.Net the same as C# ? myObject = CType(..,..) in VB.Net vs myObject = (SomeClass)aObject
1
1234
by: Sory Gomez | last post by:
How i do casting in VB .net
5
2740
by: j0mbolar | last post by:
operator = (const char *string) { if(m_string) { free(m_string); m_string = 0; } if(string) { m_string = strdup(string); } }
1
8520
by: Vic | last post by:
Hi, in VB.NET there is the following code: Friend htProvidedProperties As New Hashtable() Private Class TextboxValidatorProvidedProperties Public DataType As DataTypeConstants Public RegularExpression As String = String.Empty End Class
6
1568
by: Brett | last post by:
I find there is more casting required in C# than VB.NET. If Option Strict/Explicit is turned on, will this basically create the same environment as C# - uppercase, more casting required, must build event handlers? Thanks, Brett
20
13258
by: curious2007 | last post by:
I have the following program: #include "Vector.cpp" #include <iostream> using namespace std; template<class Arg1, class Arg2, class Result> struct binary_function
6
6014
by: mkborregaard | last post by:
Hi, I am getting an error message from MinGW that I just cannot figure what causes. The error message is: "Line 16: ISO C++ forbids declaration of 'AreaMap' with no type" My code is: #ifndef RANGE_H_INCLUDED #define RANGE_H_INCLUDED #include "grid.h" //for type: presenceGrid #include <vector>
8
7859
by: aneuryzma | last post by:
Hello, I'm merging an OpenCV app with an Ogre3d app. I'm on a mac, I'm using xCode. When I add #include "openCVApp.h" I got the following error:
0
7695
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...
1
7668
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...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
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...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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...

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.