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! | | | | re: how to use pure c to write OO programs
On 19 Oct 2005 03:49:10 -0700, zhuyin.nju@gmail.com wrote:
[color=blue]
>can some one tell that how to use pure c to write OO programs?
>
>thanks in advanced![/color]
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! | | | | re: how to use pure c to write OO programs zhuyin.nju@gmail.com wrote:[color=blue]
> can some one tell that how to use pure c to write OO programs?
>[/color]
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. | | | | re: how to use pure c to write OO programs
Le 19-10-2005, Skarmander <invalid@dontmailme.com> a écrit*:[color=blue]
> zhuyin.nju@gmail.com wrote:[color=green]
>> can some one tell that how to use pure c to write OO programs?
>>[/color]
> 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?[/color]
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 | | | | re: how to use pure c to write OO programs
EventHelix.com wrote:[color=blue]
> 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[/color]
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 | | | | re: how to use pure c to write OO programs
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 ;-) | | | | re: how to use pure c to write OO programs
Guillaume wrote:[color=blue]
> I was wondering how long it would take before someone says to use C++.
> As it turned out, almost 4 hours.[/color]
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?
[color=blue]
> Of course, you could have gone one step further and suggest ADA.[/color]
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. | | | | re: how to use pure c to write OO programs
Skarmander <invalid@dontmailme.com> writes:[color=blue]
> zhuyin.nju@gmail.com wrote:[color=green]
>> can some one tell that how to use pure c to write OO programs?
>>[/color]
> 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?[/color]
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) kst-u@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. | | | | re: how to use pure c to write OO programs
Guillaume <"grsNOSPAM at NOTTHATmail dot com"> writes:[color=blue]
> 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 ;-)[/color]
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) kst-u@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. | | | | re: how to use pure c to write OO programs
Keith Thompson wrote:[color=blue]
> Skarmander <invalid@dontmailme.com> writes:
>[color=green]
>>zhuyin.nju@gmail.com wrote:
>>[color=darkred]
>>>can some one tell that how to use pure c to write OO programs?
>>>[/color]
>>
>>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?[/color]
>
>
> I don't see the point of using a C++ frontend (presumably something
> that translates C++ to C) as opposed to a C compiler.
>[/color]
Because a C compiler won't let you compile C++. You meant "as opposed to
a C++ compiler", perhaps? Or just "write in C"?
[color=blue]
> 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.[/color]
Yes.
[color=blue]
> Assuming a C++ compiler is available for your platform, there's no
> real benefit in generating unmaintanable C as an intermediate step.
>[/color]
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).
[color=blue]
> There are ways to do OO in C, but they tend to be clumsy compared to
> using a language with OO facilities built-in.
>[/color]
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. | | | | re: how to use pure c to write OO programs
Singamsetty wrote:
[color=blue]
> 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.[/color]
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.
[color=blue]
> 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.[/color]
A citation please. | | | | re: how to use pure c to write OO programs
Skarmander <invalid@dontmailme.com> writes:[color=blue]
> Keith Thompson wrote:[/color]
[...][color=blue][color=green]
>> I don't see the point of using a C++ frontend (presumably something
>> that translates C++ to C) as opposed to a C compiler.[/color]
>
> Because a C compiler won't let you compile C++. You meant "as opposed
> to a C++ compiler", perhaps? Or just "write in C"?[/color]
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) kst-u@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. | | | | re: how to use pure c to write OO programs
Keith Thompson wrote:[color=blue]
> Skarmander <invalid@dontmailme.com> writes:
>[color=green]
>>Keith Thompson wrote:[/color]
>
> [...]
>[color=green][color=darkred]
>>>I don't see the point of using a C++ frontend (presumably something
>>>that translates C++ to C) as opposed to a C compiler.[/color]
>>
>>Because a C compiler won't let you compile C++. You meant "as opposed
>>to a C++ compiler", perhaps? Or just "write in C"?[/color]
>
>
> 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.[/color]
Yes.
[color=blue]
> 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.
>[/color]
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.
[color=blue]
> 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.
>[/color]
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. | | | | re: how to use pure c to write OO programs
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 | | | | re: how to use pure c to write OO programs
In article <1129736744.883360.269460@g14g2000cwa.googlegroups .com>, "Singamsetty" <hemanth.singamsetty@gmail.com> writes:[color=blue]
>
> 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.[/color]
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 michael.wojcik@microfocus.com
Viewers are bugs for famous brands.
-- unknown subtitler, Jackie Chan's _Thunderbolt_ | | | | re: how to use pure c to write OO programs
bwegge <bwegge@gmail.com> wrote:
[color=blue]
> 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)[/color]
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. | | | | re: how to use pure c to write OO programs
bwegge wrote:
[color=blue]
> You should read this paper on OO in ansi C -
> www.planetpdf.com/codecuts/pdfs/ooc.pdf.[/color]
I don't think that this approach to object oriented programming
is a very good idea. | | | | re: how to use pure c to write OO programs
In article <43565921$0$11068$e4fe514c@news.xs4all.nl>,
Skarmander <invalid@dontmailme.com> wrote:[color=blue]
>zhuyin.nju@gmail.com wrote:[color=green]
>> can some one tell that how to use pure c to write OO programs?
>>[/color]
>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?[/color]
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.
[color=blue]
>You could even go crazy and use, you know, an actual C++ compiler.[/color]
Comeau C++ is an actual C++ compiler.
[color=blue]
>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).[/color]
That two main hits on C++ are iostreams and exception handling.
[color=blue]
>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.[/color]
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? | | | | re: how to use pure c to write OO programs
In article <43566b9c$0$459$7a628cd7@news.club-internet.fr>,
Guillaume <"grsNOSPAM at NOTTHATmail dot com"> wrote:[color=blue]
>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 ;-)[/color]
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? | | | | re: how to use pure c to write OO programs
In article <lnd5m1o16s.fsf@nuthaus.mib.org>,
Keith Thompson <kst-u@mib.org> wrote:[color=blue]
>Skarmander <invalid@dontmailme.com> writes:[color=green]
>> zhuyin.nju@gmail.com wrote:[color=darkred]
>>> can some one tell that how to use pure c to write OO programs?
>>>[/color]
>> 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?[/color]
>
>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.[/color]
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? | | | | re: how to use pure c to write OO programs
In article <43569da5$0$11070$e4fe514c@news.xs4all.nl>,
Skarmander <invalid@dontmailme.com> wrote:[color=blue]
>Keith Thompson wrote:[color=green]
>> There are ways to do OO in C, but they tend to be clumsy compared to
>> using a language with OO facilities built-in.[/color]
>
>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?[/color]
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? | | | | re: how to use pure c to write OO programs
In article <lnr7ahm81h.fsf@nuthaus.mib.org>,
Keith Thompson <kst-u@mib.org> wrote:[color=blue]
>Skarmander <invalid@dontmailme.com> writes:[color=green]
>> Keith Thompson wrote:[/color]
>[...][color=green][color=darkred]
>>> I don't see the point of using a C++ frontend (presumably something
>>> that translates C++ to C) as opposed to a C compiler.[/color]
>>
>> Because a C compiler won't let you compile C++. You meant "as opposed
>> to a C++ compiler", perhaps? Or just "write in C"?[/color]
>
>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.[/color]
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"
[color=blue]
>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.[/color]
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? | | | | re: how to use pure c to write OO programs
In article <4356de37$0$11073$e4fe514c@news.xs4all.nl>,
Skarmander <invalid@dontmailme.com> wrote:[color=blue]
>Keith Thompson wrote:[color=green]
>> 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.[/color]
>
>Not quite. The frontend will certainly generate code you can link with
>other object files.[/color]
Maybe, maybe not.
[color=blue]
>The same is not true of your C++ compiler and C
>object files,[/color]
Maybe, maybe not.
[color=blue]
>even if you use the "same" compiler for both.[/color]
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? | | | | re: how to use pure c to write OO programs comeau@panix.com (Greg Comeau) writes:[color=blue]
> In article <lnr7ahm81h.fsf@nuthaus.mib.org>,
> Keith Thompson <kst-u@mib.org> wrote:[color=green]
>>Skarmander <invalid@dontmailme.com> writes:[color=darkred]
>>> Keith Thompson wrote:[/color]
>>[...][color=darkred]
>>>> 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"?[/color]
>>
>>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.[/color]
>
> 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"[/color]
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) kst-u@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. | | | | re: how to use pure c to write OO programs
In article <lnfyqvjw7p.fsf@nuthaus.mib.org>,
Keith Thompson <kst-u@mib.org> wrote:[color=blue]
>comeau@panix.com (Greg Comeau) writes:[color=green]
>> In article <lnr7ahm81h.fsf@nuthaus.mib.org>,
>> Keith Thompson <kst-u@mib.org> wrote:[color=darkred]
>>>Skarmander <invalid@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.[/color]
>>
>> 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"[/color]
>
>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).[/color]
Agreed.
[color=blue]
>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.[/color]
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.
[color=blue]
>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.[/color]
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? | | | | re: how to use pure c to write OO programs
On 19 Oct 2005 03:49:10 -0700, zhuyin.nju@gmail.com wrote:
[color=blue]
>can some one tell that how to use pure c to write OO programs?
>
>thanks in advanced![/color]
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? | | | | re: how to use pure c to write OO programs
On Fri, 21 Oct 2005 10:37:08 -0400, Zara <nospam.yozara@terra.es> wrote:
[color=blue]
> 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?[/color]
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 | | | | re: how to use pure c to write OO programs
"Arctic Fidelity" <spam@sacrificumdeo.net> writes:
[...][color=blue][color=green]
>> 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?[/color]
>
> 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.[/color]
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) kst-u@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. | | | | re: how to use pure c to write OO programs
EventHelix.com wrote:[color=blue]
> C++ overhead is not as high as it is generally assumed.[/color]
<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. | | | | re: how to use pure c to write OO programs
Flash Gordon wrote:[color=blue]
> EventHelix.com wrote:[color=green]
> > C++ overhead is not as high as it is generally assumed.[/color]
>
> <snip>
>
> Why tell us? We are interested in C here, not C++.[/color]
Clearly, the post(er) he replied to was not only interested in C. He
therefore had good reason to mention this.
[color=blue]
>
> 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.[/color]
Yes, he forgot to provide the previous context.
Werner | | | | re: how to use pure c to write OO programs
werasm <w_erasm@telkomsa.net> wrote:
[color=blue]
> Clearly, the post(er) he replied to was not only interested in C. He
> therefore had good reason to mention this.[/color]
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. | | | | re: how to use pure c to write OO programs
EventHelix.com wrote:[color=blue]
> C++ overhead is not as high as it is generally assumed.[/color]
Who, in heaven's name, cares? C++ is off-topic in <news:comp.lang.c>. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|