Bit Addressable Architectures

Karl Heuer karl at haddock.ISC.COM
Wed Mar 30 04:50:09 AEST 1988


In article <504 at sol.warwick.ac.uk> cudcv at cu.warwick.ac.uk (Rob McMahon) writes:
>... or does everybody but me write "malloc((strlen(s)+1)*sizeof(char))" ?

I do.  It automatically makes the argument the right type$ for malloc()
(assuming malloc's argument and sizeof's result are both unsigned, or size_t
in ANSI C); and it makes it easier to convert when you later decide that you
want to use some type other than char.  And, of course, it makes the code no
longer dependent on the questionable% sizeof(char)==1.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
Followups to comp.lang.c only.
________
$ Yes, strlen() is already a size_t in ANSI C, but this situation can also
occur with int-valued expressions.
% I don't question that it's true, just whether it's a good idea.



More information about the Comp.lang.c mailing list