[LCP]sizeof question.
Greg Black
gjb at gbch.net
Sat Sep 21 04:22:02 UTC 2002
David wrote:
| A wrote:
| > On Friday 20 September 2002 2:48 pm, you wrote:
| > #
| > # I added the case because the compiler complains if I don't.
| > # SUN Workshop, not gcc :(, unfortunaltly.
| >
| > That is most likely because you have missed out
| > #include<stdlib.h>
| > which includes the prototype for the malloc family. With this missed out the
| > compiler assumes that the return type will be int and therfore requires the
| > cast. This is the kind of error that gets masked with casts.
|
| Nope. It's there.
| I added the case because the calloc is in C file that is being included
| as part of a c++ project. It's the c++ compiler that bitches, not the C
| compiler.
I'm going to assume you mean "cast" in the various places where
you wrote "case" -- this sort of carelessness, especially where
both words are technical words, makes it difficult to help.
Anyway, to get to the point, you cannot compile C correctly with
a C++ compiler. They are different languages and have different
rules. There is legal C code which is not legal C++; and there
is legal C++ code which is not legal C. And there are things
that, although legal in both languages, do not have the same
meaning. C and C++ have very different requirements for casts.
This is a C list. You have been given C answers. If you are
trying to write C++, you need another list.
Greg
More information about the linuxCprogramming
mailing list