Click to See Complete Forum and Search --> : oop with c?
SunCore
February 1st, 2006, 10:05 PM
hi,
i heared it's possible to use oop in C.
does someone can give me a brief introduction of how it is being done?
thanks in advance
Ejaz
February 1st, 2006, 11:27 PM
Object-oriented programming in C (http://www.accu.org/acornsig/public/articles/oop_c.html)
Marc G
February 2nd, 2006, 02:24 AM
May I ask why you want to mimick OOP in C instead of using C++?
PadexArt
February 2nd, 2006, 02:29 AM
May I ask why you want to mimick OOP in C instead of using C++?
Maybe just for fun. :D
They have a show on Discovery Channel, I think it is called "Lost secrets of the Ancient World" or something like that. In that show a bunch of guys have to build bridges, cranes, ships etc using only ancient materials, technologies and tools. ;) ( not that C is ancient or anything)
sreehari
February 2nd, 2006, 03:02 AM
hi,
use oop in C.
try Object oriented Programming in c (http://www.google.co.in/search?q=Object+Oriented+Programming+in+C&sourceid=mozilla-search&start=0&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-US:official) ul get all the stuff that u need....;)
n also found This (http://www.accu.org/acornsig/public/articles/oop_c.html)
You should read this paper on OO in ansi C (www.planetpdf.com/codecuts/pdfs/ooc.pdf)
regards
RoboTact
February 2nd, 2006, 05:12 AM
There is another point: if you by some circumstances need to program in C, it's generally better to use OOP style.
PadexArt
February 2nd, 2006, 05:26 AM
There is another point: if you by some circumstances need to program in C, it's generally better to use OOP style.
Why?
NMTop40
February 2nd, 2006, 05:29 AM
You use lots of structs, construct with Create() functions and destroy with Destroy() functions.
Polymorphism is achieved with pointers to functions.
PadexArt
February 2nd, 2006, 05:35 AM
It is possible to simulate OOP in C but I'm not sure if it is worth it. If the decission to use C and not C++ was correct it means that you do not need an OOP approach and that you are aiming for something else. In that case why use OOP?
This is a more generic question actually: why force OOP on languages not designed for it? ASM, Visual Basic etc are fine languages for the tasks they were designed to. OOP is not among those tasks.
NMTop40
February 2nd, 2006, 05:37 AM
I don't get exactly why anyone would choose C nowadays.
PadexArt
February 2nd, 2006, 05:39 AM
I don't get exactly why anyone would choose C nowadays.
I think a hardcore C# programmer asks himself the very same question. :)
RoboTact
February 2nd, 2006, 05:55 AM
It is possible to simulate OOP in C but I'm not sure if it is worth it. If the decission to use C and not C++ was correct it means that you do not need an OOP approach and that you are aiming for something else.It doesn't. There may be external causes forcing to use C.
PadexArt
February 2nd, 2006, 05:56 AM
It doesn't. There may be external causes forcing to use C.
Then the decission to use C is not correct. :)
RoboTact
February 2nd, 2006, 06:22 AM
Then the decission to use C is not correct. :)There may be singleton decision space.
PadexArt
February 2nd, 2006, 06:25 AM
There may be singleton decision space.
Ouch. :D
exterminator
February 2nd, 2006, 07:12 AM
There may be singleton decision space.Correct. I definitely agree. :D ;) :thumb:
Rich2189
February 2nd, 2006, 08:28 AM
I may be completly wrong but i think you have to write DLL's in C? no?
Rich
PadexArt
February 2nd, 2006, 08:33 AM
I may be completly wrong but i think you have to write DLL's in C? no?
no. :)
microcode
February 3rd, 2006, 01:14 AM
This is a more generic question actually: why force OOP on languages not designed for it?
Because there is value in combining data and functions together into "objects". And some of the simpler concepts from OOP, like inheritance and polymorphism, can be implemented in assembly and other languages quite easily, and is just as beneficial as it is in a C++ project. But if the project requires more advanced OOP techniques like multiple inheritance or exception stack unwinding, then of course C++ is clearly a better choice.
I don't get exactly why anyone would choose C nowadays.
Some target systems, like an embedded microcontroller, may only have a C compiler available for it, and not a C++ compiler.
NMTop40
February 3rd, 2006, 07:24 AM
Some target systems, like an embedded microcontroller, may only have a C compiler available for it, and not a C++ compiler.
about time someone wrote a C++ compiler for it then.
Fadel_Saraireh
February 3rd, 2006, 07:49 AM
I have a question related to C programming:
I'm using Actionscript to create swf animition and I need to create dll files to be accessed by swf files. C is the only language supported by Macromedia Flash as they say. Are C dlls similar to C++ dlls? I mean do programs access them in the same way and they do not know which is which? Thanks
kenrus
February 3rd, 2006, 10:00 AM
In my opinion...
Programming in ANSI C in an OOP approach shouldn't automatically mean that the wrong language was chosen.
OOP is a better methodology in order to keep the code organized and generally make the programming much easier, but it doesn't automatically mean that you should be using a language that is designed for OOP.
In my experience, ANSI C is more portable across platforms than C++. Especially when your requirements include supporting several platforms (UNIX, Macintosh, Windows, Mainframe) and several versions of those platforms (Linux on Intel, Linux on Sparc, AIX OS circa 1993 and AIX OS circa 2002)
My primary job responsibilities include supporting, updating and improving a library of code that runs with just such requirements. ANSI C has proven to be the best solution. While there are some areas where code had to be specialized for a specific platform, in those cases it is just a few lines.
Sincerely,
Kendall Russell
kenrus
February 3rd, 2006, 10:02 AM
no. :)
The interface is often in C because C++ will mangle the function names.
Paul McKenzie
February 3rd, 2006, 10:12 AM
I have a question related to C programming:
I'm using Actionscript to create swf animition and I need to create dll files to be accessed by swf files. C is the only language supported by Macromedia Flash as they say.Are you sure about this? I believe that Flash is talking about a 'C' exported interface, where the function signature of the exported DLL is a 'C' interface (no mangling). The internals of the DLL function can be written in any language, including C++.
Regards,
Paul McKenzie
matthias_k
February 3rd, 2006, 10:54 AM
It may also be for the mere reason that a target library is written in object oriented C, and he wants to adapt that style (which sounds like a good idea to me).
Gtk+ is perhaps the most popular example for an object oriented sofware written in a non-OO language. I prefer gtkmm though.
Fadel_Saraireh
February 3rd, 2006, 11:08 AM
Are you sure about this? I believe that Flash is talking about a 'C' exported interface, where the function signature of the exported DLL is a 'C' interface (no mangling). The internals of the DLL function can be written in any language, including C++.
Regards,
Paul McKenzie
Paul,
These lines are taken from Macromedia Flash 8 help file:
"Advanced users can use the C-level extensibility mechanism to implement Flash extensibility files using a combination of JavaScript and custom C code. You define functions using C, bundle them in a dynamic linked library (DLL) or a shared library".
Thanks
Paul McKenzie
February 3rd, 2006, 12:11 PM
Paul,
These lines are taken from Macromedia Flash 8 help file:
"Advanced users can use the C-level extensibility mechanism to implement Flash extensibility files using a combination of JavaScript and custom C code. You define functions using C, bundle them in a dynamic linked library (DLL)The program that loads the DLL knows nothing about the language used to create the DLL's. If Flash loads the DLL's dynamically, then there is no way for Flash to know what language created the DLL. I should know, I've been creating DLL's for many years now that can be used by any language.
The only thing that may be required is that the exported function signature should be 'C' compatible, and possibly the calling convention must be either stdcall or cdecl, one or the other. After that, the internal DLL functions can be implemented in any language -- C, C++, assembler, any language that provides a 'C' exported function interface and stdcall/cdecl calling convention.
It may be easier to do it in 'C', since there are no tricks necessary to generate a 'C' function signature (for C++, you have to use the extern "C" approach, and other languages use other approaches). Probably for this reason alone, ease of setting up the DLL, is why Flash mentions 'C' and not other languages (including C++).
Regards,
Paul McKenzie
PadexArt
February 3rd, 2006, 02:18 PM
The interface is often in C because C++ will mangle the function names.
That could be a nuisance if you use the DLL through delayed loading. Otherwise you don't even feel the name mangling performed by C++.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.