[LCP]Rounding questions

Greg Black gjb at gbch.net
Sun Sep 8 21:01:06 UTC 2002


Josh Helmer wrote:

| > One odd thing is that this is one case where you did not need a
| > cast in traditional C (which needed many more casts than C89),
| > but where the 1989 standard added the requirement for a cast.
| 
| OK, now you have peaked my curiosity.  How is that possible?

Sorry, what is the question?

[Lots of stuff about void pointers and generic code elided.]

I'm not sure if you have the basics of pointers right -- it's
difficult to tell from the prose and I don't have code to look
at.

Here's the basic use:

    #include <stdlib.h>

    struct foobar *p;

    p = malloc(sizeof(*p) * 100)

As you know, malloc() returns a `void *'.  It is automatically
converted to a `struct foobar *' by the above assignment and
there is no need, in this case, for a cast (and there are good
reasons for saying that a cast here is `wrong').

Greg




More information about the linuxCprogramming mailing list