ghudson at MIT.EDU
Thu Oct 1 13:04:28 EDT 2009
On Thu, 2009-10-01 at 12:55 -0400, Jeffrey Hutzelman wrote:
> Huh? What's wrong with this?
> static inline krb5_error_code k5alloc(size_t size, void **ptrp)
> *ptrp = calloc(size, 1);
> return (*ptrp == NULL) ? ENOMEM : 0;
First and probably foremost, you'd have to cast the address of every
pointer you passed in, or you'd get a compiler warning. That's uglier
than switching around the return pointer and error code.
Second, even with the casts, it wouldn't be correct C. C (the
standardized language) does not assume that all pointer types are
represented equally. When you write "charptr = voidptr;" you give the
compiler an option to add code to convert the pointer representations.
When you cast &charptr to a void ** and assign through that, you do not.
Of course, it works fine in C (the language we actually use on platforms
anyone has ever heard of) because in reality all pointer types are
usually represented equally.
More information about the krbdev