Dumb question on dyn. mem. alloc (if(hate(novices)) dont_read();)

VLD/VMB gwyn at BRL.ARPA
Sun Jul 21 13:38:50 AEST 1985


Unless someone has patched your version of "lint" to handle malloc()
as a special case, there is no way to avoid warnings about possible
pointer alignment problems.  That is because casting from a (char *)
to a (foo *) is not possible in general.  Malloc() has been specially
designed to ensure that its returned (char *) IS properly aligned for
anything whatsoever.  "lint" does not normally know this.

By the way, I would discourage using calloc() unless you are allocating
an array of (char)s and want them to all be NUL bytes.  Since calloc()
cannot guess how you are intending to use the storage it allocates,
it is unable to fill it with the "right" type of 0 data.  You will
normally be better off using malloc() and initializing the storage
yourself.

There aren't many good books in C for the non-novice.  You might look
at Narain Gehani's "Advanced C: Food for the Educated Palate"
(Computer Science Press, 1985).



More information about the Comp.lang.c mailing list