Const Pointers and Pointer to Const are 2 different Beasts!
does the same hold for
Void Pointers and Pointers to Void ?
Const Pointers and Pointer to Const are 2 different Beasts!
does the same hold for
Void Pointers and Pointers to Void ?
"void" is not a type qualifier, so "void pointer" makes no sense.
There is no greater sign that a computing technology is worthless than the association of the word "solution" with it.
However, wikipedia refers to both of them, so i suppose they can be used inter-changeably
"The void pointer, or void*, is supported in ANSI C and C++ as a generic pointer type . A pointer to void can store an address to any data type, and, in C, is automatically casted to any other pointer type on assignment"
taken from wiki
Const pointers (const type *) and pointers to const (type *const) are different because const is a type qualifier. const can go before or after the asterisks, where it means different things, as you have discovered. void is an ordinary variable type, just like int and char and all the rest. (Well, not quite, because you can declare an int and you can't declare a void.) Anyway, type *int or type *void is invalid. You can only put the pointer type before the asterisks, not afterwards, where you can put const.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
I strongly disagree with "not quite." It's a HUGE difference. "void" is not a type. It sometimes seems to act like a type but the very fact that you cannot declare a variable of type "void" proves that it is not a type.
Void serves two completely different purposes in the language. One, you use it to declare that a function takes no arguments or has no return value. Two (completely unrelated), you use it to specify a pointer to a generic type. In one case, it indicates "nothingness." In the other case it indicates genericness.
It does NOT mean that this generic type is "void." There is absolutely NO RELATIONSHIP between "void" and "void *."
In spoken conversation I call it a "void star."
Last edited by brewbuck; 06-14-2007 at 02:13 PM.
But void has a lot more in common with int than it does with if or while. That's all I was trying to get across.
I say that if I'm pronouncing a variable name, like "void star p". But I refer to it as a "void pointer" otherwise. I'm sure other people refer to it differently.In spoken conversation I call it a "void star."
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Yes, it does resemble a typename syntactically. In fact it probably IS a typename in the formal syntax. My point, though, is that despite its SYNTACTIC similarity it doesn't serve the same purpose semantically. It's basically a new gizmo that was bolted on to the language via the type system.
Being able to manipulate pointers to undeclarable types is a pretty fundamental feature of the language that extends beyond void. Except for the syntactic trick of a function which returns or accepts the void type, there's really nothing differentiating void from any other incomplete type.
void is an incomplete type that can not be completed... and that's it. You can't really think of it as something too far outside the type system without memorizing a lot of things twice.
And if you ask me, the fact that void is the 'nothing' when used as a parameter type makes perfect sense. The only possible type you could unambiguously use for such a notation would be a type which can not be declared, which is more or less the definition of void.Code:#include <stdlib.h> // Types which can not be declared are normal and necessary to the language. struct foo; struct foo * foomalloc (size_t size) { return (struct foo *) malloc(size); } int main (void) { struct foo * f = foomalloc(5); return 0; }
Callou collei we'll code the way
Of prime numbers and pings!
You can even cast something to void, like lint likes:
You just can't declare a variable of type void, because what would it store?Code:(void)printf("Hello, World!\n");
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
I personally read "void pointer" and "pointer to void" as synonymous. Much like "int pointer" and "pointer to int".
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*