Z
zhuyin.nju
can some one tell that how to use pure c to write OO programs?
thanks in advanced!
thanks in advanced!
can some one tell that how to use pure c to write OO programs?
thanks in advanced!
1. Face a wall.can some one tell that how to use pure c to write OO programs?
Le 19-10-2005 said:1. Face a wall.
2. Take quite a few steps back.
3. Holding your head down, run towards the wall.
4. Repeat until you feel you have inflicted enough harm on yourself.
I realize this is not really helpful. Neither is pure C when it comes to
O-O programming, however.
In my opinion, you'd be much better off using a C++ frontend,
restricting yourself to basic O-O concepts while ignoring the C++ bells
and whistles that are not essential to your design. I don't know about
any frontends still out there, though ("if I want C++, I know where to
get it"). Anyone know if cfront or a clone still lives, and is of any use?
EventHelix.com said:The following article gives an example of object oriented programming
in C:
http://www.eventhelix.com/RealtimeMantra/basics/object_oriented_programming_in_c.htm
Guillaume said:I was wondering how long it would take before someone says to use C++.
As it turned out, almost 4 hours.
Of course, you could have gone one step further and suggest ADA.
Skarmander said:1. Face a wall.
2. Take quite a few steps back.
3. Holding your head down, run towards the wall.
4. Repeat until you feel you have inflicted enough harm on yourself.
I realize this is not really helpful. Neither is pure C when it comes to
O-O programming, however.
In my opinion, you'd be much better off using a C++ frontend,
restricting yourself to basic O-O concepts while ignoring the C++ bells
and whistles that are not essential to your design. I don't know about
any frontends still out there, though ("if I want C++, I know where to
get it"). Anyone know if cfront or a clone still lives, and is of any use?
Guillaume said:I was wondering how long it would take before someone says to use C++.
As it turned out, almost 4 hours.
Of course, you could have gone one step further and suggest ADA.
Oh well... lol ;-)
Keith said:I don't see the point of using a C++ frontend (presumably something
that translates C++ to C) as opposed to a C compiler.
The C generated by a translator is unlikely to be maintainable or even
legible. In ordinary usage, you're never even going to look at it;
you'll just feed it to a C compiler.
Yes.
Assuming a C++ compiler is available for your platform, there's no
real benefit in generating unmaintanable C as an intermediate step.
There are ways to do OO in C, but they tend to be clumsy compared to
using a language with OO facilities built-in.
Singamsetty said:The main characteristics of an object oriented programming are
encapsulation,
inheritance and
[run-time] polymorphism.
We can achieve encapsulation - information hiding, data abstraction - in C
(by implementing ADTs or modules) but not the other two.
C is more of a object-based programming language (not OO language).
I guess, there is a good discussion in Stroustrup's C++ book
on object-based (C-like) and OO (C++ like) paradigms.
Skarmander said:Keith Thompson wrote: [...]I don't see the point of using a C++ frontend (presumably something
that translates C++ to C) as opposed to a C compiler.
Because a C compiler won't let you compile C++. You meant "as opposed
to a C++ compiler", perhaps? Or just "write in C"?
Keith said:Skarmander said:Keith Thompson wrote:
[...]
I don't see the point of using a C++ frontend (presumably something
that translates C++ to C) as opposed to a C compiler.
Because a C compiler won't let you compile C++. You meant "as opposed
to a C++ compiler", perhaps? Or just "write in C"?
Whoops, I meant "as opposed to a C++ compiler".
BTW, a C++ frontend (translating C++ to C) in combination with a C
compiler *is* a C++ compiler.
Yes.
The fact that it uses C as an intermediate language isn't likely to
be particularly useful in any likely scenario I can think of. You
can examine the generated C code to see what symbols it uses, but you
can just as easily examine an object file, which is likely to be
about as legible.
This may be another of those "How do I drive screws without using a
screwdriver?" questions. Advising the questioner on how to hit the
screws really hard with a hammer probably isn't helpful until we find
out *why* he doesn't want to use a screwdriver.
The main characteristics of an object oriented programming are
encapsulation, inheritance and polymorphism. We can achieve
encapsulation - information hiding, data abstraction - in C (by
implementing ADTs or modules) but not the other two.
bwegge said:You should read this paper on OO in ansi C -
www.planetpdf.com/codecuts/pdfs/ooc.pdf. I don't like the use of the
(snip context-free text)
bwegge said:You should read this paper on OO in ansi C -
www.planetpdf.com/codecuts/pdfs/ooc.pdf.
1. Face a wall.
2. Take quite a few steps back.
3. Holding your head down, run towards the wall.
4. Repeat until you feel you have inflicted enough harm on yourself.
I realize this is not really helpful. Neither is pure C when it comes to
O-O programming, however.
In my opinion, you'd be much better off using a C++ frontend,
restricting yourself to basic O-O concepts while ignoring the C++ bells
and whistles that are not essential to your design. I don't know about
any frontends still out there, though ("if I want C++, I know where to
get it"). Anyone know if cfront or a clone still lives, and is of any use?
You could even go crazy and use, you know, an actual C++ compiler.
Many
produce quite acceptable code (in terms of size/speed/overhead) for
simple C++ that doesn't pull in all the STL goodies. In fact, the
initial design criteria for C++, for better or worse, included the
notion that compilers shouldn't be too burdened processing it
effectively (not much was left of this notion by the time the language
was finalized, but that's another issue).
Of course this won't help you if you don't have a C++ compiler for the
platform or if object file compatibility with C code is necessary, but
it's still worth considering.
I was wondering how long it would take before someone says to use C++.
As it turned out, almost 4 hours.
Of course, you could have gone one step further and suggest ADA.
Oh well... lol ;-)
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.