What's The Difference Between "typedef void *" and "void *"?? 
Author Message
 What's The Difference Between "typedef void *" and "void *"??

Here's a dumb question. Can anyone explain the difference between:

typedef void * pvoid ;

const pvoid  a ;
const void * b ;

My compiler claims that "a" and "b" carry different const/volatile qualifiers,
but to me they should be the same.



Mon, 03 Jul 1995 00:23:06 GMT  
 What's The Difference Between "typedef void *" and "void *"??

Quote:
Bob Riedel writes:

|Here's a dumb question. Can anyone explain the difference between:
|
|typedef void * pvoid ;
|const pvoid  a ;
|const void * b ;
|
|My compiler claims that "a" and "b" carry different const/volatile qualifiers,
|but to me they should be the same.

 Well it's easier to see the answer if you take the statements
apart like a C compiler might do it:

 pvoid  is of type pointer to void
 a      is of type const pvoid
 a      is of type const pointer to void
 b      is of type pointer to const void

Obviously they are not the same thing.

I find it much better to use the alternative placement of
storage class modifiers (const and volatile), which more
closely conveys the correct interpretation. Example:

 const void *         b; ---> void const *         b;

and ...

 const int           cI; ---> int const           cI;
 const int *        pcI; ---> int const *        pcI;
 const int * const cpcI; ---> int const * const cpcI;

Notice that the style on the right can be read easily
from right to left. I wish that the left hand syntax
was not permitted by ANSI, if only to avoid confusion.




Mon, 03 Jul 1995 08:06:03 GMT  
 What's The Difference Between "typedef void *" and "void *"??

For an answer, look at the thread "const and pointers in ANSI C" in comp.lang.c

Shankha
--
-------------------------------------------------------------------------------

CAD Language Systems, Inc.                                       (410) 992-1716
-------------------------------------------------------------------------------



Mon, 03 Jul 1995 22:37:26 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. what's the difference between void main(void) and int main(void)

2. problem with "void"

3. "void main" is a lifestyle choice

4. what is "static void usage()"?

5. printf("%p\n",(void *) ptr);

6. Displaying binary data as ascii "1"'s and "0"'s

7. Displaying binary data as ascii "1"'s and "0"'s

8. What the difference between "typedef struct" and "typedef struct tag_Struct"?

9. difference between void foo(void) and void foo()

10. '.', '::", "->"

11. from void (void*) to void (_cdecl*) (void*)

12. typedef int COMPARE(const void *, const void *);

 

 
Powered by phpBB® Forum Software