473,383 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

how to use pure c to write OO programs

can some one tell that how to use pure c to write OO programs?

thanks in advanced!

Nov 15 '05 #1
34 1793
On 19 Oct 2005 03:49:10 -0700, zh********@gmail.com wrote:
can some one tell that how to use pure c to write OO programs?

thanks in advanced!

I don´t think "pure" is the right adjective.

Use structs, pointers to structs, pointer to functions, enums.

Do not use unions.

Practise a lot.

Good Luck!

Nov 15 '05 #2
The following article gives an example of object oriented programming
in C:

http://www.eventhelix.com/RealtimeMa...mming_in_c.htm

--
EventStudio System Designer 2.5 - http://www.EventHelix.com/EventStudio
Sequence Diagram Based Real-time and Embedded System Design Tool

Nov 15 '05 #3
zh********@gmail.com wrote:
can some one tell that how to use pure c to write OO programs?

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.

S.
Nov 15 '05 #4
Le 19-10-2005, Skarmander <in*****@dontmailme.com> a écrit*:
zh********@gmail.com wrote:
can some one tell that how to use pure c to write OO programs?

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?


The comeau compiler generates C from C++:
http://www.comeaucomputing.com/
What Is Comeau C/C++ 4.3.3?

Comeau C/C++ is a command line driven C and C++ compiler that generates
platform specific and C compiler specific C as its object code (the
generated C code won't work on another platform, as it is CPU, OS and C
compiler specific, and furthermore, it is not standalone)

Marc Boyer
Nov 15 '05 #5

EventHelix.com wrote:
The following article gives an example of object oriented programming
in C:

http://www.eventhelix.com/RealtimeMa...mming_in_c.htm

--
EventStudio System Designer 2.5 - http://www.EventHelix.com/EventStudio
Sequence Diagram Based Real-time and Embedded System Design Tool

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. C is more of a
object-based programming language (not OO language). I guess, there is
a good discussion in Stroustrup C++ book on object-based (C-like) and
OO (C++ like) paradigms.

- Singamsetty

Nov 15 '05 #6
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 ;-)
Nov 15 '05 #7
Guillaume wrote:
I was wondering how long it would take before someone says to use C++.
As it turned out, almost 4 hours.
Remember, folks: propagation of Usenet posts can take anywhere from
minutes to days. You never know who reads what and when. So I guess I'm
just lucky! What did I win?
Of course, you could have gone one step further and suggest ADA.


No. I did make an effort not to stray too far from the OP's intent,
having noticed that others had already answered the question directly.
Would the question really have been answered in full without at least
the suggestion of C++, taking the possible reasons why it could have
rejected it into account?

Ada qualifies as "too far". I could have recommended Java, then; at
least that's more syntax-friendly to C programmers. If someone wants to
do O-O in C, though, there's probably a good reason why Java would be
out of the question. A C++ frontend may just have been missed as an option.

S.
Nov 15 '05 #8
Skarmander <in*****@dontmailme.com> writes:
zh********@gmail.com wrote:
can some one tell that how to use pure c to write OO programs?

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?


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. 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.

To the OP: Why do you specifically want to use pure C?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #9
Guillaume <"grsNOSPAM at NOTTHATmail dot com"> writes:
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 ;-)


And why is that amusing? C++ may well turn out to be the best
solution for the OP's problem. (Ada might not be such a bad idea
either.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #10
Keith Thompson wrote:
Skarmander <in*****@dontmailme.com> writes:
zh********@gmail.com wrote:
can some one tell that how to use pure c to write OO programs?

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?

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"?
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.

That is:
- assuming there *is* a C++ compiler of sufficient quality available
(and "quality" may also imply "low overhead", which is certainly an
issue for many C++ compilers);

- assuming you do not need low-level compatibility with C (name
mangling, linkage etc.; some of this will play a role with a frontend
too, but is likely far easier to cope with).
There are ways to do OO in C, but they tend to be clumsy compared to
using a language with OO facilities built-in.


Precisely. Which is why my first advice is: don't do it. The second is:
if you *must* get C for some reason (you need to interface directly with
existing C code, your compiler supports only C) and you *must* use an
O-O design (for reasons I can't make up, but there undoubtedly will be
some) why *not* a frontend?

S.
Nov 15 '05 #11
Singamsetty wrote:
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.
Not quite.
The C computer programming language supports encapsulation
but not data hiding.
Opaque data types are only an inferior attempt at data hiding.
C supports data abstraction in a number of ways
including typedefs and structs.
C structs are used to introduce User Defined Types (UDTs)
which can implement Abstract Data Types (ADTs).
C does *not* support inheritance
so programmers are obliged to cast [pointers] to the base type.
C programmers have always implemented run-time polymorphism
using jump tables (virtual function tables).
The standard FILE type is an example of run-time polymorphism.

Search Google Groups

http://groups.google.com/

for

comp.lang.c Object-Oriented Programming (run-time polymorphism) with C99

Please find attached a copy of the "Shape class" example from
Bjarne Stroustrup, "The C++ Programming Language: Third Edition",
Chapter 2: A Tour of C++, Section 6: Object-Oriented Programming,
Subsection 2: Class Hierarchies, pages 38-40 implemented in C99.
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.


A citation please.
Nov 15 '05 #12
Skarmander <in*****@dontmailme.com> writes:
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. 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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #13
Keith Thompson wrote:
Skarmander <in*****@dontmailme.com> writes:
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.

Not quite. The frontend will certainly generate code you can link with
other object files. The same is not true of your C++ compiler and C
object files, even if you use the "same" compiler for both. Especially
if we can disregard issues of overloading, multiple inheritance and all
that malarkey.

Of course, this means pointing out that expecting linkage from and to C
to "magically" work out means you're counting on your implementation's
amenities to save the day, which may or may not be acceptable. If the
intent is portable C++ code even *without* the frontend (that is, you
want the compiler to be *fully* transparent) it's not good enough.
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.


And possibly it is, making an educated guess about why he wouldn't want
to use it. Of course, I could guess wrong. Such is life. Caveat lector,
you get what you pay for, etc. :-)

S.
Nov 15 '05 #14
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
preprocessor in this paper, but thats just me. Also Scott Meyers book
"Effective C++: 50 ways .." gives good insight into how C++ works, and
can be recommended if you want to make OO in C. I found it very
helpful, when trying to do OO in C.

Basically, you will find it very difficult (if not impossible) to do
stuff like (operator) overloading and automatic calls to
constructors/destructors. Inheritance and virtual methods (essence of
OO) is fairly straight forward to do, but the biggest problem is not
doing OO in C. It is getting those who read your code a year from now
to understand what you are doing. OO in C looks very complicated and is
in my experience a good way to make your code more error prone. In
other words, dont go there unless you absolutely have to.

Regards
Bwegge

Nov 15 '05 #15

In article <11**********************@g14g2000cwa.googlegroups .com>, "Singamsetty" <he*****************@gmail.com> writes:

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.


Utter rot. C doesn't provide syntactic sugar for polymorphism, but
there's nothing preventing you from implementing it manually. The
same can be said of inheritance, unless you use an overly-restrictive
definition of the term.

And, of course, it's always possible to implement one Turing-complete
language in another.

This has been discussed ad nauseum here.

--
Michael Wojcik mi************@microfocus.com

Viewers are bugs for famous brands.
-- unknown subtitler, Jackie Chan's _Thunderbolt_
Nov 15 '05 #16
bwegge <bw****@gmail.com> wrote:
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)


It is proper Usenet etiquette to include the relevant portions of the text
you are replying to. To do this using Google groups, please follow the
instructions below, penned by Keith Thompson:

If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #17
bwegge wrote:
You should read this paper on OO in ansi C -
www.planetpdf.com/codecuts/pdfs/ooc.pdf.


I don't think that this approach to object oriented programming
is a very good idea.
Nov 15 '05 #18
In article <43***********************@news.xs4all.nl>,
Skarmander <in*****@dontmailme.com> wrote:
zh********@gmail.com wrote:
can some one tell that how to use pure c to write OO programs?
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?


Comeau C++, currently not based on cfront, generates C as an
internal phase of translation, is going strong. However, not
knowing the underlying reason for the OPs query, it's unclear
if that's what the OP is seeking.
You could even go crazy and use, you know, an actual C++ compiler.
Comeau C++ is 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).
That two main hits on C++ are iostreams and exception handling.
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.


We get can compilers going rapidly, but as above, not sure these
things touch on the OPs query.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 15 '05 #19
In article <43*********************@news.club-internet.fr>,
Guillaume <"grsNOSPAM at NOTTHATmail dot com"> wrote:
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 ;-)


Are you suggesting that it shouldn't be suggested?
Since C does not directly support many of the conceptual
mappings as directly, mentioning C++ is a reasonable
thing to do.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 15 '05 #20
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote:
Skarmander <in*****@dontmailme.com> writes:
zh********@gmail.com wrote:
can some one tell that how to use pure c to write OO programs?

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?


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. 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.


Indeed, there is little point in just compiling to C.
Especially as usually that alone is insufficient.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 15 '05 #21
In article <43***********************@news.xs4all.nl>,
Skarmander <in*****@dontmailme.com> wrote:
Keith Thompson wrote:
There are ways to do OO in C, but they tend to be clumsy compared to
using a language with OO facilities built-in.


Precisely. Which is why my first advice is: don't do it. The second is:
if you *must* get C for some reason (you need to interface directly with
existing C code, your compiler supports only C) and you *must* use an
O-O design (for reasons I can't make up, but there undoubtedly will be
some) why *not* a frontend?


Because there is another way to phrase the question:
Why not just use C++, of any form? As Keith pointed out
the generated C code is not going to be a new maintainable
source code. This is not to say there is never any benefit
to such an arrangementi (or I've led myself astray for 20 year :})
but the C code in and of itself is not a solution; the solution
is an integrated mechanism to object the desired and eventual
native object code. (Again, assuming this is what the OP
is after.)
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 15 '05 #22
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote:
Skarmander <in*****@dontmailme.com> writes:
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.


Then your statement is unclear, because it seems to be saying
"I don't see the point of using a C++ compiler as opposed to a
C++ compiler"
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.


If it's not particularly useful, then neither are other
intermediate forms. I think I'm not understanding the above.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 15 '05 #23
In article <43***********************@news.xs4all.nl>,
Skarmander <in*****@dontmailme.com> wrote:
Keith Thompson wrote:
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.
Not quite. The frontend will certainly generate code you can link with
other object files.


Maybe, maybe not.
The same is not true of your C++ compiler and C
object files,
Maybe, maybe not.
even if you use the "same" compiler for both.


Maybe, maybe not.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 15 '05 #24
co****@panix.com (Greg Comeau) writes:
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote:
Skarmander <in*****@dontmailme.com> writes:
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.


Then your statement is unclear, because it seems to be saying
"I don't see the point of using a C++ compiler as opposed to a
C++ compiler"


Yes, I was probably unclear.

A C++ compiler, regardless of what intermediate language it might use,
is a good tool for writing OO programs (assuming, for the sake of
argument, that C++ is a good language for OO programs).

If your goal, as the subject of this thread says, is to "use pure c to
write OO programs", a C++ compiler that produces C as an intermediate
is not likely to be particularly useful (unless the C++ compiler
somehow manages to generate maintainable C code). I can imagine it
might be useful in some circumstances: if the target machine has a C
compiler but no C++ compiler, and the C++/C translator generate
suffciently portable C code that it can be compiled for the target.

But since the original poster has never bothered to come back and
clarify what he's looking for, there's not much point in speculating.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #25
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote:
co****@panix.com (Greg Comeau) writes:
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote:
Skarmander <in*****@dontmailme.com> writes:
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.
Then your statement is unclear, because it seems to be saying
"I don't see the point of using a C++ compiler as opposed to a
C++ compiler"


Yes, I was probably unclear.

A C++ compiler, regardless of what intermediate language it might use,
is a good tool for writing OO programs (assuming, for the sake of
argument, that C++ is a good language for OO programs).


Agreed.
If your goal, as the subject of this thread says, is to "use pure c to
write OO programs", a C++ compiler that produces C as an intermediate
is not likely to be particularly useful (unless the C++ compiler
somehow manages to generate maintainable C code). I can imagine it
might be useful in some circumstances: if the target machine has a C
compiler but no C++ compiler, and the C++/C translator generate
suffciently portable C code that it can be compiled for the target.
I thought you originally said something like that, and agreed. :)
Furthermore, you will really never get the generated code to be truly
the "new source code", though lots and lots of work can go into
such a thing, and of course that goal would not seem directly beneficial
especially since there are other choices.
But since the original poster has never bothered to come back and
clarify what he's looking for, there's not much point in speculating.


Still agreed. :)
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 15 '05 #26
On 19 Oct 2005 03:49:10 -0700, zh********@gmail.com wrote:
can some one tell that how to use pure c to write OO programs?

thanks in advanced!

OP has never reappeared, although there have been some nice debates
going on, and his/her presence has been requested...
will he/she be a stone-throwing troll?

Nov 15 '05 #27
zh********@gmail.com a écrit :
can some one tell that how to use pure c to write OO programs?


This can help

http://ldeniau.home.cern.ch/ldeniau/html/oopc/oopc.html

--
C is a sharp tool
Nov 15 '05 #28
On Fri, 21 Oct 2005 10:37:08 -0400, Zara <no***********@terra.es> wrote:
OP has never reappeared, although there have been some nice debates
going on, and his/her presence has been requested...
will he/she be a stone-throwing troll?


It's possible. ;-) I do have one question though. Throughout this
discussion, I have seen a lot of talk about C++ and overhead. I'm just
curious about a scenario like this.

Say you are normally a C user (like me) but for some reason you may, for
one reason or another, require or desire the usage of real OOP facilities
in the language you are using. It seems that OOP in ANSI C is a bit iffy,
and C++ is rather "large" by what I gather (and I am rather
inexperienced), but, I have not heard anyone discuss Objective-C. It was
my understanding that Objective-C was more of a wrapper on C (using that
word loosely), and would better fit the requirements of a C user who
wanted to add OOP into the language, but perhaps not all the extra stuff
of C++. Am I wrong here?

I would appreciate any of you who could comment on this. I have sometimes
wondered if something I wanted might be better implemented in OOP, and I
have thought about Objective-C, but I have not really understood where
they all stand for the normal C user who wants OOP.

Thanks,

- Arctic Fidelity
Nov 15 '05 #29
"Arctic Fidelity" <sp**@sacrificumdeo.net> writes:
[...]
OP has never reappeared, although there have been some nice debates
going on, and his/her presence has been requested...
will he/she be a stone-throwing troll?


It's possible. ;-) I do have one question though. Throughout this
discussion, I have seen a lot of talk about C++ and overhead. I'm just
curious about a scenario like this.

Say you are normally a C user (like me) but for some reason you may,
for one reason or another, require or desire the usage of real OOP
facilities in the language you are using. It seems that OOP in ANSI C
is a bit iffy, and C++ is rather "large" by what I gather (and I am
rather inexperienced), but, I have not heard anyone discuss
Objective-C.


We don't discuss Objective C here because it isn't C.

There is a comp.lang.objective-c newsgroup.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #30
C++ overhead is not as high as it is generally assumed.

The following articles compare the differences in generated code:

http://www.eventhelix.com/RealtimeMa...erformance.htm

http://www.eventhelix.com/RealtimeMa...rformance2.htm

--
EventStudio System Designer 2.5 - http://www.EventHelix.com/EventStudio
Sequence Diagram Based System Design and Object Modeling Tool

Nov 15 '05 #31
EventHelix.com wrote:
C++ overhead is not as high as it is generally assumed.


<snip>

Why tell us? We are interested in C here, not C++.

If it was in response to some previous post here, then provide context
since the post you are responding to may well not have reached everyone
your post reached.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #32

Flash Gordon wrote:
EventHelix.com wrote:
C++ overhead is not as high as it is generally assumed.
<snip>

Why tell us? We are interested in C here, not C++.


Clearly, the post(er) he replied to was not only interested in C. He
therefore had good reason to mention this.

If it was in response to some previous post here, then provide context
since the post you are responding to may well not have reached everyone
your post reached.


Yes, he forgot to provide the previous context.

Werner

Nov 15 '05 #33
werasm <w_*****@telkomsa.net> wrote:
Clearly, the post(er) he replied to was not only interested in C. He
therefore had good reason to mention this.


The point is that comp.lang.c++ is available if people want to discuss
that language.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #34
EventHelix.com wrote:
C++ overhead is not as high as it is generally assumed.


Who, in heaven's name, cares? C++ is off-topic in <news:comp.lang.c>.
Nov 15 '05 #35

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hung Jung Lu | last post by:
Hi, I have been looking into AOP (Aspect-Oriented Programming) for sometime, now. I frankly don't like the syntax of any of the approaches I have seen so far. I am kind playing around with some...
6
by: rxl124 | last post by:
someone please please help w/ this one. As I been working on this on and off and it just does not want to work. 1 #!/usr/bin/perl -w 2 3 $file = "/home/user1/dothis"; 4 open(FILE, ">$file");...
9
by: Dario | last post by:
This is a technical C++ post regarding the Microsoft runtime error R6025 Pure Virtual Function Call that sometime occurs in programs compiled with Microsoft Visual C++ 6.0. Please consider the...
4
by: A man | last post by:
Hi, what does the assignment " = 0 " signify in the pure virtual function declaration virtual void f() = 0 ; what gets the value "0" ? regards, Aman .
11
by: santosh | last post by:
Hello, I was going through the Marshal Cline's C++ FAQ-Lite. I have a doubt regarding section 33.10. Here he is declaring a pure virtual destructor in the base class. And again defining...
3
by: junky_fellow | last post by:
I have read certain articles that encourage to use/write pure functions (if possible) as they are better suited for optimization. I got one example that expalins how the code can be optimised....
3
by: dkultasev | last post by:
Hello, I am looking for the C++ software. I mean I need to write programs on pure C++ but I want software with good debugger to be able watch variables and so on. Of course I can use notepad +...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
15
by: Anna Smidt | last post by:
Sorry, I have a question again: I am trying to debug/ release a CLR application (that uses the FrameWork). No when I try to compile it, it stops in this line in -------mmintrin.h-------- ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.