LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 08-17-2005, 07:00 AM   #1
ssg14j
LQ Newbie
 
Registered: Jul 2005
Posts: 12

Rep: Reputation: 0
How to write a object oriented c program?


How to write a object oreinted c program?

give me one example.....
 
Old 08-17-2005, 07:02 AM   #2
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
There are ways to program OO in C. This is called "Objective-C".

After a google search: http://www.google.se/search?hl=sv&q=...%B6kning&meta=
 
Old 08-17-2005, 10:47 AM   #3
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
AFAIK Objective-C is its own language, not really "C". Doing object oriented programming in C is very possible, for instance the Linux kernel uses OO techniques heavily. Just remember that C doesn't have language support for these features, so you have to roll your own objects, inheritence, polymorphism, etc. Inheritence is easily done via structs (structure slicing or having one struct as part of another) and polymorphism can be accomplished with lookup tables of function pointers (so one function dispatches to another based on the type of object it's called on). It's not the prettiest looking code in the world, but it works. I wrote a whole game back in ggrad school using these techniques (it was part of an assignment) and iot worked quite well. You can study the Linux kernel, particularly stuff like the VFS layer, to see an example of constructs like this in action.
 
  


Reply


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
How to write a object oriented program using c ssg14j Programming 6 08-10-2005 09:56 AM
How are object-oriented languages transformed to GCC's RTL ? desmond5 Programming 0 04-17-2005 01:38 AM
perl object Oriented Programming Question eastsuse Programming 1 08-20-2004 12:29 PM
Problem with "Object Oriented Concepts" Mohsen Programming 6 03-24-2004 12:21 AM
Object-Oriented Design Citizen Bleys Programming 2 02-11-2002 01:25 PM

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

All times are GMT -5. The time now is 02:00 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