473,837 Members | 1,457 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 9804


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
8272
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 this: http://www.cplusplus.com/doc/tutorial/tut5-4.html
4
3111
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
9143
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
1247
by: Sory Gomez | last post by:
How i do casting in VB .net
5
2751
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
8526
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
1578
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
13310
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
6027
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
7882
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
9843
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
9682
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10875
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
10566
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...
0
10272
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7001
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5669
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5848
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3124
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.