Path: utzoo!mnetor!uunet!husc6!bbn!rochester!udel!mmdf From: dsill@nswc-oas.arpa (Dave Sill) Newsgroups: comp.sys.amiga Subject: Re: 'void *' (was Re: malloc() prob. on 3.4a) Message-ID: <2144@louie.udel.EDU> Date: 19 Apr 88 14:15:08 GMT Sender: mmdf@udel.EDU Lines: 56 Matt Dillon writes: >Dave Sill writes: >:That's when you use a cast. You can't simply pretend all pointers are >:`void *'. It's just not right. And what happens when someone tries >:to compile your code with a compiler that doesn't handle `void *'? > > Damn It! It's just not right! It makes little sense to declare > AllocMem() as returning char * when you know it doesn't! But it does! Just because you're using the return values as if they were different types doesn't change the fact that it's declared as one single type, probably `char *'. > Which is worse? Saying a function returns something it doesn't and > using casts, or saying a function can return several (pointer) > types ala void * and not use casts? That's not the right question. Either way you're declaring a function to return one type and converting the return value to what you need. The choice is between using `char *' and casts versus `void *' and no casts. The first method, let's call it the K&R method, works on ALL C compilers: past, present and future. Absolutely guaranteed. The second, or ANSI method, works on only those compilers that claim to conform to the latest draft. > What happens when someone tries to compile my code with a > compiler that doesn't handle enumerations? > > What happens when someone tries to compile my code with a > compiler that doesn't handle structure assignments? > > What happens when someone tries to compile my code with a > compiler that doesn't handle structure return values? > > What happens when someone tries to compile my code with a > compiler that doesn't understand what a signed char is? > > ... Get the point? Yeah, I do. But it's not the same. There have never been any guarantees about structure assignment, structure return values, or `enum' types. They, like `void *', were additions to C. Do you get my point? All C compilers correctly handle the conversion of `char *' to pointer to anything; few have `void *'. Why should you let your laziness get in the way of the portability of your code to other Amiga C compilers? Why not type a few extra casts just to be sure? How much effort does it really take to do it right? ========= The opinions expressed above are mine. "In case of doubt, decide in favor of what is correct." -- Karl Kraus