LinuxQuestions.org
Visit Jeremy's Blog.
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 12-13-2005, 01:41 AM   #1
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Rep: Reputation: 30
Porting Code


Would anyone mind translating this code for me?
The code was extracted from the book design patterns
And i want to port it to Linux and it is based on Subject : Observer model

class Subject;

class Observer {
public:
virtual ~Observer();
virtual void Update (Subject* theChangedSubject) = 0;
protected:
Observer();
};

class Subject {
public:
virtual ~Subject();

virtual void Attach (Observer *);
virtual void Detach (Observer *);
virtual void Notify();
protected:
Subject();
private:
List<Observer *> *_observers;
};


void Subject::Attach (Observer *o)
{
_observers->Append(o); // I used push_back(o); here
// but Segmentation Fault
}

void Subject:etach (Observer *o)
{
_observers->Remove(o); // I used remove(o) here
}

void Subject::Notify()
{
ListIterator<Observer *> i(_observers);
// in Linux C++, ListIterator doesn't exist
for (i.First(); !i.IsDone(); i.Next()) {
i.CurrentItem()->Update(this);
}
}

..... and so on so forth.
Thanks
Jack
 
Old 12-13-2005, 05:53 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
What makes you think that there's any porting required?
Looks like plain C++ to me, with no OS dependencies I
can spot off the top of my head.


Cheers,
Tink
 
Old 12-14-2005, 01:24 AM   #3
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
Tinkster,
Thanks for the advice, I have had it solved. But forgot how I did this. Thanks
Jack
 
Old 12-14-2005, 09:34 PM   #4
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
Another porting question, when VC/BC generates __fastcall prologue, it would generally modify the structure of the opening idioms of the routine, does Linux has the same stuff cos my app is real time (time-critical)..
Thanks
Jack
 
Old 12-14-2005, 09:57 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Actually, I understand that Gcc gives you options to bypass the stack altogether and use registers for passing parameters (at least on some versions, on some platforms).

In any case, Gcc definitely gives you a LOT of choices, on ALL platforms.

Here are a couple of links that might be useful:

http://www.linuxjournal.com/article/7269

http://www.tldp.org/HOWTO/Assembly-HOWTO/gcc.html

http://www.samspublishing.com/articl...30865&seqNum=5

http://www.linuxgazette.com/issue71/joshi.html
 
Old 12-14-2005, 10:11 PM   #6
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
So all the optimizations are done during compilation (commandline). But you can't use any directives to specify optimizations in code?
Thanks
Jack
 
  


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
porting win code quarry_06 Programming 3 11-24-2004 10:41 PM
Porting C++ code from XP to Linux Bondfire Programming 7 08-12-2004 03:42 PM
Porting C++ code from windows to Linux ashwinipahuja Programming 9 06-03-2004 02:09 AM
Porting c++ code to linux Moons Programming 3 06-03-2004 01:24 AM
porting windows ce code to linux rainmann Programming 7 06-12-2003 07:19 AM

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

All times are GMT -5. The time now is 04:08 AM.

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