5

There are a lot of excellent answers how can one simulate object oriented concepts with C. To name a few:

When is it appropriate to use such simulation and not to use languages that support object-oriented techniques natively?

Highly related:

Community
  • 1
  • 1
Roman Byshko
  • 8,591
  • 7
  • 35
  • 57
  • 3
    It is ***never*** correct to re-post because you didn't like a close. Argue your case in the comments, flag for a moderator or post to meta. – dmckee --- ex-moderator kitten Nov 30 '11 at 22:22
  • @dmckee Have you looked into P.S.? – Roman Byshko Nov 30 '11 at 22:22
  • Why yes, I have. I have, indeed. – dmckee --- ex-moderator kitten Nov 30 '11 at 22:23
  • @dmckee I reformulated my question using advice of another user. My question was added by two users to favorites, so I think other people are also interested. – Roman Byshko Nov 30 '11 at 22:24
  • Cris is welcome to his opinion about what makes for a suitable question for Stack Overflow. I see a distinction without a difference. – dmckee --- ex-moderator kitten Nov 30 '11 at 22:26
  • Edit/correct/improve your original question http://meta.stackexchange.com/questions/25520/is-it-ever-acceptable-to-re-post-a-closed-question-e-g-after-editing-it-to-be – Bart Nov 30 '11 at 22:26
  • @Bart I did not know about this policy. I will. (I thought it went completely out of view being closed.) – Roman Byshko Nov 30 '11 at 22:28
  • @dmckee I do not understand why you act so angrily like I commited a big crime. You can check my comments and flag weight. I do care that only high quality and such that respect FAQ are asked here. People have voted and closed my previous question without no comment or suggestion how to improve it. And you are crying right away also. Show some respect please. – Roman Byshko Nov 30 '11 at 22:39
  • @dmckee And why it's **never** correct to repost? Because you have answered this question in meta and it get as little as 3 votes? – Roman Byshko Nov 30 '11 at 22:51
  • @RomanB This is not the place to discuss this. Take it to [META] if you feel like discussing this further. But be ready to be pointed at similar questions as I have done above. – Bart Nov 30 '11 at 22:56
  • @RomanB: I've made the same mistake in the past. Bart's advice is good. On the issue of questions being closed without comment, I used to think like you, but there are reasonable arguments to suggest that the burden of always adding comments might make SO less efficient. See, for example http://meta.stackexchange.com/questions/29531/should-a-user-have-to-add-a-comment-when-they-vote-to-close – Cris Nov 30 '11 at 23:29
  • You may find Object Oriented Programming in ANSI C book useful. It is available for free here - http://silversoft.net/docs/ooc.pdf –  Nov 30 '11 at 23:30
  • @VladLazarenko Hi, Vlad. I've found it earlier here on SO. Thanks. – Roman Byshko Nov 30 '11 at 23:30
  • @AlfP.Steinbach Can you please say something on this question? – Roman Byshko Dec 04 '11 at 04:40

3 Answers3

4

I'll give you the one reason I know of because it has been the case for me:

When you are developing software for a unique platform, and the only available compiler is a C compiler. This happens quite often in the world of embedded microcontrollers.

e.James
  • 116,942
  • 41
  • 177
  • 214
  • Which say nothing to suggest the cramming a OO approach onto c is a good idea (though it is entirely possible). – dmckee --- ex-moderator kitten Nov 30 '11 at 22:25
  • 3
    @dmckee: I disagree. OO concepts have proven to be *very* useful, especially for large projects. If you are stuck with a C compiler, why not try to employ as much OO as possible? – e.James Nov 30 '11 at 22:27
2

To just give you another example: a fair amount of the x86 Linux kernel is using C as if it were C++, when object-orientation seems natural (eg, in the VFS). The kernel is written in assembly and C (if that wasn't changed in the 3.0 kernel). The kernel coders create macros and structures, sometimes even named similar to C++ terms (eg, for_each_xxx), that allow them to code as-if. As others have pointed out, you'd never choose C if you start a heavily object-oriented program; but when you're adjusting C based code to add object-oriented features, you might.

gnometorule
  • 2,151
  • 2
  • 20
  • 29
1

When you want a cross-platform foundation for object-oriented APIs. A case in point is Apple's Core Foundation. Being entirely C, it could be easily ported, yet provides an extremely rich set of opaque objects to use.

A nice example of its flexibility is the way many of its types are 'toll-free' bridged with those from Foundation (a set of true OO Objective-C libraries). Many types from Core Foundation can be used, fairly naturally, in Foundation APIs, and vice-versa. It's hard to see this working so well without some OO concepts being present in the Core Foundation libraries.

Cris
  • 1,939
  • 3
  • 23
  • 37