Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-04-2010, 07:47 PM   #1
LQ Newbie
Registered: Mar 2010
Posts: 2

Rep: Reputation: 0
Conerting HP UNIX C++ pgm to Linux C++ using g++

I am converting suits of our HP UX c++ programs to run on linux server.
I've come across a strange problem.

I assign a string to a character pointer passed as an argument to a function
void XYZ( const char *ptr ) {
String X( ptr );
The above fails with a Segmentation Fault (SF) - but not always (see below).

But if I change the code to read:
void XYZ( const char *ptr ) {
String X;
X = ptr;
The code doesn't give a SF. Both forms of assignment should be legal. The strange thing is if I compile a simple program with the first or second construct, it does NOT SF.

Any suggestions, examples, tools to convert hp ux c++ program to linux c++ program will be much appreciated

Old 03-04-2010, 08:03 PM   #2
LQ Guru
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
I think you are focusing on the symptom rather than the cause.

It is very common for a SF to occur far from its actual cause.

It is very common for a code change near the point of the symptom and very far from the cause to fix the symptom. That creates the illusion that you are looking at the cause.

Looking at code around the symptom is generally fruitless. Experimenting with code changes around the symptom is usually worse.

Most SF's need to be diagnosed with a debugger. Catch the actual SF in action and look at the values of the relevant variables. If you know any asm, it is much more effective to look at the register values and the disassembly of code leading up to the SF. That gives a much more trustworthy answer than having the debugger report local variable values.

Once you know the bad value that caused the SF, you can start backtracking toward the cause.

BTW, do you happen to be converting from 32 bit architecture to 64 bit architecture at the same time you are switching from HP UX to linux and at the same time as I assume you are switching to gcc from either a different compiler or at least a different version of gcc?

If you are switching 32 bit to 64 bit, try not switching. You can build and run 32 bit Linux programs on 64 bit Linux. If that works, it might give you more insight into the nature of the underlying bug.

Last edited by johnsfine; 03-04-2010 at 08:07 PM.
Old 03-05-2010, 12:09 AM   #3
LQ Newbie
Registered: Mar 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for your comment/help.
Much appreciated.

Thanks again


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
c++ prog on unix to convert PGM file into RGB singh.vikas85 Programming 2 05-15-2009 12:35 AM
c++ in linux to read a PGM file (portable graymap) onto the memory and print hight singh.vikas85 Linux - Newbie 4 05-06-2009 08:14 PM
LXer: Unix - System VI Release Notes - More Linux and Unix Humor LXer Syndicated Linux News 0 12-06-2008 04:30 PM
Unix Book for Beginners (Not Linux... Unix) suse2166 General 6 11-25-2004 12:46 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:40 PM.

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