Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to use pure c to write OO programs

Reply
Thread Tools

how to use pure c to write OO programs

 
 
zhuyin.nju@gmail.com
Guest
Posts: n/a
 
      10-19-2005
can some one tell that how to use pure c to write OO programs?

thanks in advanced!

 
Reply With Quote
 
 
 
 
Zara
Guest
Posts: n/a
 
      10-19-2005
On 19 Oct 2005 03:49:10 -0700, 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!

 
Reply With Quote
 
 
 
 
EventHelix.com
Guest
Posts: n/a
 
      10-19-2005
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

 
Reply With Quote
 
Skarmander
Guest
Posts: n/a
 
      10-19-2005
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.
 
Reply With Quote
 
Marc Boyer
Guest
Posts: n/a
 
      10-19-2005
Le 19-10-2005, Skarmander <> a écrit*:
> 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
 
Reply With Quote
 
Singamsetty
Guest
Posts: n/a
 
      10-19-2005

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

 
Reply With Quote
 
Guillaume
Guest
Posts: n/a
 
      10-19-2005
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
 
Reply With Quote
 
Skarmander
Guest
Posts: n/a
 
      10-19-2005
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.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-19-2005
Skarmander <> writes:
> 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) kst- <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.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-19-2005
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) kst- <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Pure space directly inside div ignored, but pure space directlyinside span honored liketofindoutwhy@gmail.com HTML 4 03-29-2008 06:06 PM
What do i use to write programs in Windows? Weasel C++ 16 11-08-2005 08:36 PM
Pure functions still pure after definition Todd Aspeotis C++ 3 05-30-2005 03:53 AM
Script-kiddies use C to write evil programs ! ! ! Brian Raab C Programming 6 10-06-2004 08:19 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57