Path: utzoo!mnetor!uunet!husc6!bbn!rochester!udel!mmdf From: dsill@nswc-oas.arpa (Dave Sill) Newsgroups: comp.sys.amiga Subject: Re: malloc() prob. on 3.4a Message-ID: <2095@louie.udel.EDU> Date: 15 Apr 88 19:30:09 GMT Sender: mmdf@udel.EDU Lines: 56 Leo 'Bols Ewhac' Schwab writes: >In article <315@unicom.UUCP> mille_g@unicom.UUCP (Shane 'spin1' Miller) writes: >>Leo has kind of set a convention of making a lot of intuition funcs() return >>void --> void *OpenScreen(). Then in the code he has: s=OpenScreen(&sdef); >>... >... I'm casting them to return a void * (pointer to ------- >nothing), which is a generic pointer which can be assigned to any other kind >of pointer. You aren't casting them, you're *declaring* them. Draft proposed ANSI C (section 3.2.2.3 Oct. '86): "A pointer to `void' may be converted to a pointer to an object of any type. A pointer to an object of any type may be converted to a pointer to `void' and back again; the result shall compare equal to the original." That's not exactly a "generic pointer". It more like a box that can hold any pointer. > You may accuse me of being lazy, but it works, and I think it makes >my code more readable. I don't think it improves readability. It seems to me you have the choice of doing either: Glorp *GetGlorp(); Glorp a_glorp; a_glorp = GetGlorp(); or void *GetGlorp(); Glorp a_glorp; a_glorp = GetGlorp(); In my opinion, the first is more readable because GetGlorp() returns a pointer to a Glorp(), not a pointer to nothingness. Additionally, the former works on non-ANSI compilers. > Can anyone think of a compelling reason why I should >explicitly [declare] stuff? Well, for one thing, `void *' only works with so-called ANSI-compatible compilers. Another problem is that you are redeclaring the Intuition functions, and the dpANS requires all declarations in scope for a function to match. You might be able to get away with it, but I don't think it's a good idea. ========= The opinions expressed above are mine. "The 80x86 world has no excuse for the mess it has gotten itself into." -- Doug Gwyn