LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2005, 03:43 AM   #1
dand
LQ Newbie
 
Registered: Dec 2004
Posts: 18

Rep: Reputation: 0
dynamic casts


A program that I ported to linux from windows is crashing due to dynamic casting. The program works fine on windows but when run on linux, any time a dynamic_cast is encountered, it crashes. Before I do the cast, the pointer is valid, but when I try to access the new object pointer thereafter, it fails every time!

If I change it to be a static_cast, everything is ok.

I have read that RTTI is automatically turned on for linux.

Has anyone seen this before or do you know what is happening.

Cheers, Dan.
 
Old 06-15-2005, 04:59 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Even though dynamic_cast checks for a valid conversion and also converts references, I think I'd rather avoid inverse casts in the first place and use static_cast. Are you using dynamic_cast for the type checking for a inverse cast? If you are, then you need to be checking the result for NULL before you use it, unless you are using references, which will cause an exception if the cast is bad. If dynamic_cast is used then RTTI should be on (I think it's on by default for gcc), otherwise I wouldn't think it would compile. The bottom line is: if you aren't casting a base class pointer to a derived class pointer and want it to check to see if it's valid at runtime, you should use static_cast.
ta0kira
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
saving web casts f1gm3nt Linux - General 1 07-26-2005 01:20 PM
Getting Dynamic IP eponymous Linux - Networking 5 10-09-2004 06:08 PM
Dynamic name resolution for dynamic IP merlin740 Linux - Software 2 10-04-2004 05:56 PM
Dynamic IP? Gerardoj Linux - Networking 5 05-27-2003 02:20 PM
dynamic IP........ anoop_chandran Linux - General 4 11-25-2001 01:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration