why still use C?

F

Fergus Henderson

cody said:
no this is no trollposting and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.

One important advantage of C is that C is significantly simpler than C++.
 
R

Richard Heathfield

cody said:
no this is no trollposting

I will try to bear that in mind.
and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.

i heard people say C++ is slower than C but i can't believe that.

Believe it. Or test it. For your test to be significant, be sure you use a
wide range of test programs, equivalently written in C and C++ (don't
bother with the so-called "C subset" of C++ - either write in C or write in
C++), on a wide variety of programs. Tabulate your results. (If they're
worth a damn, they're probably worth publishing, perhaps on your Web site
in the first instance.)
in
pieces of the application where speed really matters you can still use
"normal" functions or even static methods which is basically the same.

Suck it and see.
in C there arent the simplest things present like constants,


int main(void)
{
const int new = 6; /* I rest my case */
return 0;
}
each struct
and enum have to be prefixed with "struct" and "enum".

Poor baby.
iam sure there is
much more.

Yes, there is. C is simple, portable, and very very fast. Those are
important qualities.
i don't get it why people program in C and faking OOP features(function
pointers in structs..) instead of using C++. are they simply masochists or
is there a logical reason?

There is a logical reason. Encapsulation is a great idea for some projects
(not all, of course), so why not use it (when appropriate)? Note, also,
that a C program such as you describe doesn't "fake OOP features" - rather,
it uses OOP to achieve its objectives. That C, which was /not/ designed to
do OOP, /can/ be used for OOP is quite remarkable in itself. Having said
that, I am very much of the "if you want OOP and C++ is available, use C++"
school - but note that C++ is /not/ available on anything like as many
target platforms as C is.
i feel C has to benefit against C++.

It does have three important advantages. It's simple, portable, and fast.
 
D

Douglas A. Gwyn

cody said:
i heard people say C++ is slower than C but i can't believe that. in pieces
of the application where speed really matters you can still use "normal"
functions or even static methods which is basically the same.

There is both a speed and size penalty for using C++ where
pain C would do. The penalty isn't as bad as it used to be.
in C there arent the simplest things present like constants, each struct and
enum have to be prefixed with "struct" and "enum". iam sure there is much
more.

C has constants. We usually use typedefs rather than struct
and enum tags.
i don't get it why people program in C and faking OOP features(function
pointers in structs..) instead of using C++. are they simply masochists or
is there a logical reason?

It's very rare for C programs to "fake OOP features".

One of C's main benefits is that it is easier to implement
and has simpler run-time support requirements. This makes
it especially suited to embedded processors, for example.
 
S

Sven Semmler

cody said:
no this is no trollposting and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.

C is available on nearly every machine. C++ is not. OOP is a nice thing
but not for everything.

"With OOP we can solve problems very elegant, we wouldn't have without
it."

While the above statement is not entirely true, there is some truth in it.
;)

/Sven
 
D

Doc O'Leary

"cody said:
no this is no trollposting and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.

C++ *is* C. Worse, it is an improper superset of C. Of all the things
you might advocate as an "alternative" to ANSI C, C++ is probably the
worst.
i don't get it why people program in C and faking OOP features(function
pointers in structs..) instead of using C++.

This is laughable. It is C++ that is best known for faking OO features!
If you're looking for an OO extension to C that is actually well done,
one that is additionally a proper superset of C, you should be looking
at Objective-C. But that's still in the C family. If you don't want C,
don't use C; don't use C++ and pretend you're not using C, though.
 
J

Jeremy Yallop

cody said:
in C there arent the simplest things present like constants, each struct and
enum have to be prefixed with "struct" and "enum".

Neither of these is really true. "Real" integer constants can be
created using enums (or "#define"), and you can use "typedef" to avoid
having to write "struct" or "enum" everywhere if it bothers you, e.g.:

typedef enum { false, true } bool;

Jeremy.
 
F

fermath

Hi all

My reason is simple: I have no time at the moment to learn C++ and C fits my
needs.

Well, I actually know something about C++, but I feel that you need a lot of
knowledke on C++ to be able to develop "big programs", I mean that there are
lots of things that need to be well understood, otherwise you are dead (you
know, lot of errors you can't find...)

cody said:
no this is no trollposting and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.

i heard people say C++ is slower than C but i can't believe that. in pieces
of the application where speed really matters you can still use "normal"
functions or even static methods which is basically the same.

in C there arent the simplest things present like constants, each struct and
enum have to be prefixed with "struct" and "enum". iam sure there is much
more.

i don't get it why people program in C and faking OOP features(function
pointers in structs..) instead of using C++. are they simply masochists or
is there a logical reason?

i feel C has to benefit against C++.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
 
E

E. Robert Tisdale

cody said:
I am very curious about why people still use C
instead of other languages, especially C++.

Fear of change.
I heard people say C++ is slower than C but I can't believe that.

Neither can I. In fact, I know it isn't true.
No one has *ever* shown an example of C code
which is faster that C++ (or slower than C code)
that actually performed the same computation.
The speed of the code emitted by either a C or C++ compiler
depends *only* upon the quality of the the compiler.
In pieces of the application where speed really matters,
you can still use "normal" [C] functions or even static methods
which is basically the same.

It doesn't matter.
In C, there aren't the simplest things present like constants,

C supports the const keyword now.
each struct and enum must be prefixed with "struct" and "enum".

typedef struct X {
// public data members
} X;

in C is the same as

struct X {
// public data members
};

in C++.
I am sure there is much more.

I don't get it why people program in C and faking OOP features
(function pointers in structs..) instead of using C++.
Are they simply masochists? Or is there a logical reason?

I feel C has to benefit against C++.

They are *not* faking OOP features.
This is just the way that C programmers wrote object oriented programs
before the C++ programming language was introduced.
The C++ programming just makes object oriented programming
easier, more reliable and more portable -- that's all that
*any* so called object oriented programming language can do.
 
T

Thomas Matthews

cody said:
no this is no trollposting and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.

i heard people say C++ is slower than C but i can't believe that. in pieces
of the application where speed really matters you can still use "normal"
functions or even static methods which is basically the same.

C++ is not slower than C. Many early C++ compilers would translate C++
to C, then proceed as a C compiler.

in C there arent the simplest things present like constants, each struct and
enum have to be prefixed with "struct" and "enum". iam sure there is much
more.

No, this is just a typing issue. All those things disappear during code
execution. One can use the typedef facility for making abbreviations.

i don't get it why people program in C and faking OOP features(function
pointers in structs..) instead of using C++. are they simply masochists or
is there a logical reason?

Many people have to deal with legacy code. Some OOP features have been
coded in C and have been tested. Converting them to C++ means more
development and testing time.
i feel C has to benefit against C++.

Each language has its thorns and roses. I just asked if I could use C++
on our next embedded project and the management said no.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
S

Serve La

Glen Herrmannsfeldt said:
Well, some people consider C as a glorified assembler. It isn't quite that,
especially as it has changed over the years, but not so far off.

Yes, let's talk about that. When I code in C for my favorite platform I do
tend to "see" the generated assembly in my head. The picture gets bigger and
changes too as I gain more experience, but I do think a lot more like that
machine when programming in C. When I do C++ this is a lot less, I tend to
think in terms of objects and generated objects (templates). Can't decide
what I like better, I keep switching back and forth between the two.

consider this:
size_t i = strcspn(s, "\n");
std::string::size_type i = s.find_first_of("\n");

In my mind strcspn does it a lot simpler than find_first_of.

Or even simpler.
strlen(s);
s.length();

What does s.length() example do? Do strlen somewhere? (some implementations
do). Keep track of the length?
You just give up a lot of control with C++.
 
S

Santa Claus

It'll be right next to the place reserved for people who
sling mud anonymously.

If your criticism has merit

Notice that it is a personal opinion, based on my experience. Yours might
differ, and you are welcome to that.
(I know too little of C++ to
evaluate it), have the courage to put your name to it.

What name? How do we know, anyway, that any names at the end of a post
correspond to the poster? Is it going to make you happier if I sign as
James S. Taylor? Or as Madhusudan Patel? Or as Pierre Mattera? Can you
tell if any of those is my real name? What difference does it make?
If the courage is lacking, what are we to make of your confidence in
your own opinion?

Make whatever you want.
And if you have so little confidence in it, why bother us with it?

Wrong conclusion from the wrong premise. You can't conclude anything
from my posting about my relative lack of confidence in any anything.
May the next chimney you slide down have a roaring fire
at the bottom.

Hmm... We touched a raw nerve here :)
 
G

Gabriel Dos Reis

| > In C, there aren't the simplest things present like constants,
|
| C supports the const keyword now.

but variables of integral types declared with the "const" keyword and
initialized with literals do not qualify as "integral constant expressions".
E.g.

const int nine = 9;

enum { NINE = nine }; // ERROR in C, OK in C++

-- Gaby
 
S

Sidney Cadot

where the exception goes is well defined, it cannot go somewhere, it goes
simply down the callstack which is more readable than gotos, imo.

"Simply down the callstack" is a bit of an oxymoron - this has some
severe and rather complicated consequences in case the callstack that is
being partially pop()ed contains partially executed
constructor/destructor calls, for example. Of course it is possible to
handle this properly, my only point is that it is complicated. Too
complicated for me, anyway - but of course you may be one of that rare
breed of programmers that understands what is going on in these cases.
If so: congratulations, and more power to you! :)

The nice thing about exceptions is that the code throwing it shouldn't
care who catches it. This does not blend well with my preferred way of
working where I can keep track of the execution flow. Subjective.

Exception handling in C++ can result in code that is significantly
bloated and slower, by the way. The C++ compiler needs to insert
instrumentation code to handle exceptions in any function that can
possibly be the target of an exception, as far as I understand.
but doesn't c support structured exception handling too? i heard something
like that.

Not that I'm aware of. You do have setjmp/longjmp which allows to
effectively save and restore the stack state, and this can be used to
implement something similar, but that's it, as far as I know.
[Non-portable templates]
that is not true. name me one example where semantics are different on
different compilers!

My latest try on doing something with templates was with a C++ compiler
for a Trimedia embedded processor, which failed to compile a rather
simple program with a template class, giving me an internal compiler
error. (this was about 2 years ago when I was graduating - can't
reproduce the program I'm afraid). Back in those days, compilers were
rife with problems in their template implementations.

I just did a search on Google for recent reports on this and (apart from
some rants on VC++ 6.0 templates), I get relatively little results.
Perhaps people have cleaned up their act (I don't know), so I guess it's
only fair to retract this statement since I cannot back it up with
anything other than old experience. My apologies... I just hope somebody
could step in at this point and give a couple of relevant examples to
prove me right after all.
templates are a very very useful and mighty feature in c++. however it is a
bit difficult to use.

On that we agree.
yes and no. c++ should not be used for everything. gui's should not be made
with c++.

Fact is that a very large percentage of GUIs _is_ made with C++.
for libraries, c++ is good because it is very fast and flexible thanks to
templates.

Except that it is difficult to link such a library with proprietary
software - these usually only support linking to C code. This severely
limits the usefulness of such libraries.
you say the language design has failed, but do you have a better idea how it
can be solved?

No. I'm waiting for people smarter than I am to come up with a new
paradigm :)
imo for high performance applications there is no better way than c++. since
c lacks of templates, c++ would be the choice for me.

I'm comfortable with that. People differ, that's generally a good thing.
I haved C++ also on occasion, for a rather small self-contained data
processing application that just cried out for a (simple) class
hierarchy. It depends a lot on the type of project, I suppose.
right i cannot imagegine that somebody really and completely understands the
STL.

Oh I can imagine that. I just hope these people don't expect the same of me!

Best regards, Sidney
 
M

Mark McIntyre

On Mon, 06 Oct 2003 03:00:01 +0200, in comp.lang.c , Sidney Cadot

(actually I'm replying to Cody - my server lost his message)

I missed your original post, but as far as I'm concerned, the answer
is "occam's razor".
When I'm writing a simple tool to process raw data from one stream to
another, its faster (for me) to /write/ it in C, even tho C++ probably
has zero or little runtime penalty.

But whats the point of using C++ if all you do is "dumb it down" till
it matches C?

C has constants. I'm not sure what your point is about prefixing
types. Don't you like knowing what type a type is? If so, use
typedefs.

IMHO only a theoretical scientist or someone without a C++ compiler
would fake up C++'s OOP with C. If you want OOP, then use C++. OR a
language that does it even better.
 
S

Sidney Cadot

James said:
[linking to proprietary sw]

It seems to me that only this last issue truly addresses the question.
In all of your other issues, you're complaining about features of C++
that you don't have to use if you don't want to.

To a certain extent you are right of course, but the original question
mentioned 'faking' OOP-techniques in C quite explicitly, so I answered
under the assumption that cody's focus was on using OOP from either C or
C++. I really do feel that a great deal of discomfort of C programmers
with C++ is that they aren't particularly fond of OOP programming for a
variety of reasons - I know that's true for me. In my mind at least, C++
equals C plus syntactic sugar plus classes plus exceptions plus
templates. Surely you can use C++ without using the complexities brought
in by {classes, exceptions, templates}. But then, why not stick to C99?

By the way I am quite comfortable with other people having a different
opinion on this, I really think that the fun in programming is largely
dependent on one's comfortability with one's choice of language. I know
people who love coding in C++, Java, Lisp, Prolog, Haskell,... fine for
me. I love C (and a bit of Python nowadays), but there's no need to turn
this into a holy war. When somebody asks me 'why do you prefer X over Y'
I think I can make a case on technical merits but reality is never
black or white.
I personally use C or C++ for the simple reason that our company's
contract with NASA requires us to deliver code for either Fortran 77,
Fortran 90, C90 (more precisely, C94), or Ada.

Interesting! I code for ESA, and for my current project we were
basically free to choose. Could've gone with Java or C++ as far as ESA
was concerned, but since it was a requirement to link the library to IDL
and Matlab we decided to stick with C94 on technical merits. No regrets.
I like C because it's a simpler language than C++, and because I've
got a lot more experience with it. However, I love complicated things,
and I see all kinds of interesting features in C++ that I'd love to
have time to play with.

As for myself I'd like to have some more time to play with functional
languages, I like the compactness with which some things can be
expressed. I tend to think of OOP and C++ as extensions to the
imperative paradigm, for that reason I think there's more to learn for
me by studing a functional language.
However, as long as all of my C++ programming
is done at home, rather than at work, I'm never going to build up much
experience with it. I'm hpping that the next project I work on allows
both C++ and C99 (which also has some neat new features that aren't in
C++).

I can imagine that could be fun. And perhaps that would be a good excude
for brushing up those generic programming skills, from what I gather
from Google they're really portable nowadays! :)

Best regards,

Sidney
 
S

Sidney Cadot

James said:

Oops! I same to have had the wrong message selected when trying to reply
to you. Please check my 0:12am message to Mark McIntyre for a response.

I beg everyone's pardon!

Sidney
 

Ask a Question

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.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top