Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!email!vmars!hp From: hp@vmars.tuwien.ac.at (Peter Holzer) Newsgroups: comp.lang.c Subject: Re: "void **" : Is it valid and what does it mean? Message-ID: <1991May28.115914.19879@email.tuwien.ac.at> Date: 28 May 91 11:59:14 GMT References: <6001@goanna.cs.rmit.oz.au> Sender: news@email.tuwien.ac.at Distribution: comp Organization: Technical University of Vienna, Dept. for Realtime Systems Lines: 49 Nntp-Posting-Host: nowhere.vmars.tuwien.ac.at ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: [...good explanation why void ** isn't a pointer to any pointer deleted...] >> Basically what I want is a type that would coerce to a pointer to a >> pointer to a type, for any type. Sort of one level beyond simple >> "void *". >Why do you want to do _that_? If you _could_ do it, you would be >throwing away information that the receiver would need in order to >be able to _use_ the thing? What's the context? I don't know what the original poster wanted to do, but since I was in the same situation once, I can give you an example why anybody would like to do something like that. In MARS (a real-time system developed at our department) exists a system-call which is now defined as: int receivem (msg_name name, void * msg, unsigned short flags); Messages are (in C) defined as structures and there are several types. For some reason, which is not relevant here, msg is not a pointer to the structure, but a pointer to a pointer to structure. Of course one common error is to define a struct foo * mymsg and then pass mymsg instead of &mymsg. With the current prototype this error is not detected by the compiler, but if some type `pointer to any pointer' existed, this type of error could be catched. Unfortunately this is not possible in C. #pragma speculation_mode on /* :-) */ There is a rumor among C-programmers that `all struct-pointers smell the same.' (I could not find any assertion of this in the standard, and I can find pro's and con's for such a rule, so I call it a rumor, undoubtedly someone who knows will tell me if it is correct or not). If this rumor is true, a pointer to pointer to any struct would be legal (At least there is no reason why it should not be legal). So we could declare the systemcall above as: int receivem (msg_name name, struct ** msg, unsigned short flags); which is almost exactly what the designer of the system call had in mind. -- | _ | Peter J. Holzer | Think of it | | |_|_) | Technical University Vienna | as evolution | | | | | Dept. for Real-Time Systems | in action! | | __/ | hp@vmars.tuwien.ac.at | Tony Rand |