Some general questions about C and good practice

J

jmcgill

KimmoA said:
Any C++ program is per
definition (of its creator, Bjarne Stroustrup) also a C program

I haven't done a thorough search of Bjarne's book, but I certainly don't
recall ever seeing any statement to that effect. Even when C++ was
implemented primarily as a C preprocessor filter, it was strongly
regarded as an entirely separate language.
 
J

jmcgill

KimmoA said:
Yes, but any well-written C is supposed to compile as a C++ program.
That's what I meant. Sorry.

Stroustrup says no such thing. He does say:

"With minor exceptions, C++ is a superset of C (meaning C89, defined by
ISO/IEC 9899:1990). Most differences stem from C++'s greater emphasis
on type checking. Well-written C programs tend to be C++ programs as
well. A compiler can diagnose every difference between C++ and C."

He also says:

"...[G]reat importance was attached to retaining a high degee of
compatability with C;... this precluded cleaning up the C syntax."
 
D

Default User

jmcgill said:
KimmoA said:
Yes, but any well-written C is supposed to compile as a C++ program.
That's what I meant. Sorry.

Stroustrup says no such thing. He does say:

"With minor exceptions, C++ is a superset of C (meaning C89, defined
by ISO/IEC 9899:1990). Most differences stem from C++'s greater
emphasis on type checking. Well-written C programs tend to be C++
programs as well. A compiler can diagnose every difference between
C++ and C."

He also says:

"...[G]reat importance was attached to retaining a high degee of
compatability with C;... this precluded cleaning up the C syntax."


He also said, ". . . good C programs tend to be C++ programs. For
instance, every program in [K&R 2] is a C++ program."

Now, that last bit is an exaggeration, as much of K&R 2 uses implicit
in in a number of places. Anyway, I think that statement is where the
"every C program is a C++ program" idea tends to come from.




Brian
 
J

jmcgill

Default said:
He also said, ". . . good C programs tend to be C++ programs. For
instance, every program in [K&R 2] is a C++ program."

You have an edition/page number for that?
 
K

Keith Thompson

KimmoA said:
Yes, but any well-written C is supposed to compile as a C++ program.
That's what I meant. Sorry.

That's not right either.

There is rarely any good reason for well-written C to avoid using
"new", "delete", "class", etc. as identifiers.

And well-written C definitely shouldn't cast the result of malloc()
(doing so can mask errors).

The only exception is when you have some real requirement to write
code that will compile as either C or C++. In real life, such a
requirement is almost vanishingly rare.

If you want to write C++, do so. If you want to write C++ while
restricting yourself to a C-like subset of the language, you're free
to do that as well. But if you want to write C, just write C.
 
F

Frederick Gotham

KimmoA posted:
Yes, but any well-written C is supposed to compile as a C++ program.
That's what I meant. Sorry.


Incorrect. See Keith's reasons up-thread (to name but a few).
 
K

KimmoA

I have now looked it up (yes -- I just HAD to!). Instead of quoting all
you people have said, I'll just write a reply.

In "The C++ Programming Language" (Special Edition), on the bottom of
page 13 (chapter 1, section 1.5), he (Bjarne) says:

"However, good C programs tend to be C++ programs. For example, every
program in [The C Programming Language book], is a C++ program."

This must be where I got it from. Sure... I misquoted him, but it's
been a while since I read it. You can't say that it's entirely false,
though!
 
K

KimmoA

KimmoA said:
I have now looked it up (yes -- I just HAD to!). Instead of quoting all
you people have said, I'll just write a reply.

All "that" you people have said; a "general" reply. Sigh. I'm being too
trigger-happy with the big, red, shiny "post" button...
 
C

CBFalconer

Keith said:
.... snip ...

The only exception is when you have some real requirement to write
code that will compile as either C or C++. In real life, such a
requirement is almost vanishingly rare.

Such as when you are selling cloaked C source that is likely to be
compiled by idiots who don't know how to specify a C compilation,
and you don't want to waste your time holding their quivering
little hands.
 
M

Martin Ambuhl

KimmoA said:
Yes, but any well-written C is supposed to compile as a C++ program.
That's what I meant. Sorry.

That's garbage. Yes, I know that BS has that printed in various of his
C++-pushing books, but it is a lie. When BS says "any well-written C
program" he means "any C program that obeys the style that I, BS, have
laid down and is the same as I, BS, have laid down for C++." The fact
is that his version of "well-written C program" involves many things
that are at least stylistic blunders in C. If you want to quote BS
about C++, feel free to do so in come appropriate forum, which
comp.lang.c is not, but almost everything he says about C amounts to
self-promotion and C++ advocacy. He is no authority on "well-written C".
 
M

Martin Ambuhl

KimmoA said:
I have now looked it up (yes -- I just HAD to!). Instead of quoting all
you people have said, I'll just write a reply.

In "The C++ Programming Language" (Special Edition), on the bottom of
page 13 (chapter 1, section 1.5), he (Bjarne) says:

"However, good C programs tend to be C++ programs. For example, every
program in [The C Programming Language book], is a C++ program."

This must be where I got it from. Sure... I misquoted him, but it's
been a while since I read it. You can't say that it's entirely false,
though!

Since it is entirely false, I se no reason to avoid saying so. It is
also entirely false for you to claim that we can't say that it's
entirely false. It is *not* true that "good C programs tend to be C++
programs." It is probably true that C programs that BS writes tend to
be C++ programs, but who cares?
 
K

KimmoA

Martin said:
That's garbage. Yes, I know that BS has that printed in various of his
C++-pushing books, but it is a lie. When BS says "any well-written C
program" he means "any C program that obeys the style that I, BS, have
laid down and is the same as I, BS, have laid down for C++." The fact
is that his version of "well-written C program" involves many things
that are at least stylistic blunders in C. If you want to quote BS
about C++, feel free to do so in come appropriate forum, which
comp.lang.c is not, but almost everything he says about C amounts to
self-promotion and C++ advocacy. He is no authority on "well-written C".

Hmm... "BS" sounds like something else...

Why can't I quote Bjarne about C++ here? I'm not saying that it's the
Truth, or that I even agree with it. It's just a quote. I actually got
the feeling that Bjarne in fact likes C.
 
R

Richard Heathfield

KimmoA said:
Martin said:
[Bjarne Stroustrup] is no authority on "well-written C".

Hmm... "BS" sounds like something else...

Why can't I quote Bjarne about C++ here?

But you did, so obviously you can. But it's not a good idea; this is
comp.lang.c, not comp.lang.c++. If you want to talk about C++, it might be
better to do so in comp.lang.c++, yes?
 
K

KimmoA

Richard said:
But you did, so obviously you can.

"Can't" as in... "can't"! :)
this is comp.lang.c, not comp.lang.c++. If you want to talk about C++, it might
be better to do so in comp.lang.c++, yes?

Yes, but I'm a C coder. The C++ reference(s) seemed relevant in the
discussion.
 
M

Martin Ambuhl

KimmoA said:
Martin Ambuhl wrote:
Why can't I quote Bjarne about C++ here? I'm not saying that it's the
Truth, or that I even agree with it. It's just a quote. I actually got
the feeling that Bjarne in fact likes C.

Who said you can't. I certainly didn't. I wrote that comp.lang.c was
not an appropriate newsgroup for posting about some other language. We
don't give a rat's ass about C++ or about what BS has to say about it.
If you insist on posting about C++ in comp.lang.c, or about Lisp in a
COBOL newsgroup, or about Forth in a Fortran newsgroup, you can do that
too. But you are also free to join all the other off-topic toads in the
killfile.
 
R

Richard Bos

KimmoA said:
Yes, but any well-written C is supposed to compile as a C++ program.

Then C++ has failed fundamentally, because most well-written C programs
of any reasonable complexity do not compile as C++.

Richard
 
R

Richard Bos

KimmoA said:
In "The C++ Programming Language" (Special Edition), on the bottom of
page 13 (chapter 1, section 1.5), he (Bjarne) says:

"However, good C programs tend to be C++ programs. For example, every
program in [The C Programming Language book], is a C++ program."

This must be where I got it from. Sure... I misquoted him, but it's
been a while since I read it. You can't say that it's entirely false,
though!

I not only _can_ say that it's entirely false, I _do_ say that it's
entirely false, and if Bjarne really wrote that, more than a little
dishonest of him.

Richard
 
C

Charlton Wilbur

KimmoA said:
In "The C++ Programming Language" (Special Edition), on the bottom of
page 13 (chapter 1, section 1.5), he (Bjarne) says:

"However, good C programs tend to be C++ programs. For example, every
program in [The C Programming Language book], is a C++ program."

This must be where I got it from. Sure... I misquoted him, but it's
been a while since I read it. You can't say that it's entirely false,
though!

I not only _can_ say that it's entirely false, I _do_ say that it's
entirely false, and if Bjarne really wrote that, more than a little
dishonest of him.

It's also entirely possible that at the time he wrote that, it was
true -- C++ did evolve out of C, after all. It seems to me that
"dishonest" involves more intent than I think can be accurately
ascribed here.

(On the other hand, the larger point, that C and C++ are stylistically
very different, and good C and good C++ do not tend to resemble each
other, remains valid despite what Dr Stroustrup may have written.)

Charlton
 

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

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top