Is it a good thing that program mix C and C++?

B

Bill Pursell

Malcolm McLean said:


When "just can't happen" relies on a basic level of human competence, we
can count on it happening at least 17 times a day, 260 days a year.

And 170 times a day the other 105.25 days. Emphasis on
"at least".
 
K

Kenneth Brody

Kenny McCormack wrote:
[...]
The point is that is you consider the following three commonly harped on
things in this NG:

1) char a[10]; x = a[10];
2) void main()
3) char *x = (char *) malloc(10);

The first is clearly an error. The 2nd probably, and the third, really not.
Yet all three are harped upon with equal vigor, by a bunch of freaks who
don't understand the concept of degree.

However, there are times when a newbie mentions that the reason
for putting the cast on malloc in the first place was to stop the
compiler from complaining about the int-to-pointer conversion.

While one might argue that the forgotten include won't happen in
"production code", the audience for clc is much wider than those
who write C for a living.

Yes, the cast is "harmless" if you have the proper #include. But,
it appears to be a relatively common newbie error to forget the
necessary #include, and they learned somewhere that you can "shut
up" the compiler by adding the cast, rather than by fixing the
root cause of the problem.

Now, I have an excuse for casting the return at times -- I learned
C in pre-void days, when the cast was necessary. Those days are
long gone, but old habits are hard to break. (Just try typing the
word "print" without a "f" magically appearing after it.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
D

Dave Vandervies

Kenneth Brody said:
Those days are
long gone, but old habits are hard to break. (Just try typing the
word "print" without a "f" magically appearing after it.)

More than once, while writing English text, I've used the word "gets"
and then gone back to put an 'f' at the beginning.


dave
 
C

Chris Hills

Is it a good thing that program mix C and C++?

If you mean in the same file NO.

If you mean can you call other modules written in C from a C++ program
then that is OK. Many libraries are written in C

However you should not be compelling C in a C++ compiler

C++ is based on C90 and has diverged one way whilst C99 went a
different way.
 
J

John Bode

Is it a good thing that program mix C and C++?

You certainly do *not* want to mix C and C++ idioms in the same source
file (e.g., using new to allocate memory and free() to deallocate it),
but you can certainly have different source files written in different
languages; you just have to pay attention to linkage rules and
parameter passing conventions.
 

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
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top