473,378 Members | 1,401 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,378 software developers and data experts.

C++ application which crashes in dynamic_cast

Hi,

I have a c++ application which crashes in this line (from the debugger,
I have a segmentation fault here):
void *object = dynamic_cast<void>(aObject);
I have stepped thru the code in debugger and the 'aObject' pointer is
Not null. So can you please tell me, what else can go wrong so that my
program crashes in this line?

Thank you. for any help.

Code:

NS_IMETHODIMP
nsTraceRefcntImpl::LogAddCOMPtr(void* aCOMPtr,
nsISupports* aObject)
{
#if defined(NS_BUILD_REFCNT_LOGGING) &&
defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR)
// Get the most-derived object.
void *object = dynamic_cast<void>(aObject); // crashes in this
line????
//......

}

Jan 17 '07 #1
4 6651
"yi*****@gmail.com" <yi*****@gmail.comwrote in
news:11**********************@l53g2000cwa.googlegr oups.com:
Hi,

I have a c++ application which crashes in this line (from the debugger,
I have a segmentation fault here):
void *object = dynamic_cast<void>(aObject);
I have stepped thru the code in debugger and the 'aObject' pointer is
Not null. So can you please tell me, what else can go wrong so that my
program crashes in this line?

Thank you. for any help.

Code:

NS_IMETHODIMP
nsTraceRefcntImpl::LogAddCOMPtr(void* aCOMPtr,
nsISupports* aObject)
{
#if defined(NS_BUILD_REFCNT_LOGGING) &&
defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR)
// Get the most-derived object.
void *object = dynamic_cast<void>(aObject); // crashes in this
line????
//......

}

dynamic_cast to a void? I thought you had to either dynamic_cast to either
a pointer (and check the return value for NULL) or a reference (and be
prepared for a bad_cast exception).
Jan 17 '07 #2

That is code from others. But i would like to investigate when the
program crashes at that line.

Thank you.

Andre Kostur wrote:
"yi*****@gmail.com" <yi*****@gmail.comwrote in
news:11**********************@l53g2000cwa.googlegr oups.com:
Hi,

I have a c++ application which crashes in this line (from the debugger,
I have a segmentation fault here):
void *object = dynamic_cast<void>(aObject);
I have stepped thru the code in debugger and the 'aObject' pointer is
Not null. So can you please tell me, what else can go wrong so that my
program crashes in this line?

Thank you. for any help.

Code:

NS_IMETHODIMP
nsTraceRefcntImpl::LogAddCOMPtr(void* aCOMPtr,
nsISupports* aObject)
{
#if defined(NS_BUILD_REFCNT_LOGGING) &&
defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR)
// Get the most-derived object.
void *object = dynamic_cast<void>(aObject); // crashes in this
line????
//......

}


dynamic_cast to a void? I thought you had to either dynamic_cast to either
a pointer (and check the return value for NULL) or a reference (and be
prepared for a bad_cast exception).
Jan 17 '07 #3
yi*****@gmail.com wrote:
Hi,

I have a c++ application which crashes in this line (from the debugger,
I have a segmentation fault here):
void *object = dynamic_cast<void>(aObject);
I have stepped thru the code in debugger and the 'aObject' pointer is
Not null. So can you please tell me, what else can go wrong so that my
program crashes in this line?

Thank you. for any help.

Code:

NS_IMETHODIMP
nsTraceRefcntImpl::LogAddCOMPtr(void* aCOMPtr,
nsISupports* aObject)
{
#if defined(NS_BUILD_REFCNT_LOGGING) &&
defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR)
// Get the most-derived object.
void *object = dynamic_cast<void>(aObject); // crashes in this
line????
//......

}
The cast should be to void*, not to void.

Per 5.2.7, it is legal to dynamic cast to void* (specifically 5.2.7/1
and 5.7.7/7).

To be honest, I'm surprised your fragment compiled if it really is
<voidand not <void*>.

Jan 17 '07 #4
yi*****@gmail.com wrote:
>
That is code from others. But i would like to investigate when the
program crashes at that line.
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
Jan 17 '07 #5

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

Similar topics

13
by: GianGuz | last post by:
Everyone knows about the complex and cpu-expensive procedures taken by dynamic_cast to find the right function call in a virtual classes hierarchy. The question I would to rise is when...
3
by: Axter | last post by:
I'm wondering about the practical use of dynamic_cast in reusable or generic code. I'm currently working on a smart pointer that can be used on vector and other STL containers. See following...
1
by: Steven T. Hatton | last post by:
The result shown below doesn't surprise me now. But it did several months ago when I followed some bad advice and tried to check if I had a live object at the address referenced by a pointer. Can...
3
by: Ganesh | last post by:
On devx site, I saw following code. It says when a derived class is tried to cast to base type, it looks at the missing vtable and complains if the object is already deleted. I am of the opinion...
0
by: none | last post by:
Hello I have created a realtime data intensive application in C++/CLI. Data streams into this application through a set of ActiveX controls. For example, each stock symbol will be assigned to...
22
by: Boris | last post by:
I'm porting code from Windows to UNIX and ran into a problem with dynamic_cast. Imagine a class hierarchy with three levels: class Level2 derives from Level1 which derives from Base. If you look...
1
by: Sandy | last post by:
HI All, I have created a MFC exe using VC++ .NET 2003 on Windows XP Prof service pack 2 and it works properly on my machine, but when I run the same exe on a different machine (Windows XP Prof...
15
by: Grizlyk | last post by:
Hello. Returning to question of manual class type identification, tell me, for ordinary inheritance is C++ garantee that dynamic_cast<Derived*>(Base*) can be implemented similarly to ...
25
by: lovecreatesbea... | last post by:
Suppose I have the following three classes, GrandBase <-- Base <-- Child <-- GrandChild The following cast expression holds true only if pBase points object of type of ``Child'' or...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.