473,385 Members | 1,487 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 sFactoryCreationFunc =
::rtl::OUString::createFromAscii("createDataAccess ToolsFactory");>

- getDbToolsClientFactoryFunction() = reinterpret_cast<createDataAccessToolsFactoryFunct ion>(>

+ // reinterpret_cast<createDataAccessToolsFactoryFunct ion> removed for gcc permissive >
+ getDbToolsClientFactoryFunction() = (createDataAccessToolsFactoryFunction)(>

osl_getSymbol(getDbToolsClientModule(), sFactoryCreationFunc.pData));

Any comments or better solutions appreciated.

KenF
Jul 19 '05 #1
3 9767


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
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...
4
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...
1
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
by: Sory Gomez | last post by:
How i do casting in VB .net
5
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
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...
6
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...
20
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
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...
8
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:
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

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.