On 13 Jan 2006 23:15:06 -0800, in comp.lang.c , "lovecreatesbeauty"
<> wrote:
>Why (type*)pointer isn't equal to *(type**)pointer,
it is, if you do it right. In this case however, you're converting
between different types of pointer which may not work since different
pointer types may be stored differently (alignment, size, bitpattern
etc)..
> 1 int main(void)
don't put line numbers in code snippets, I don't plan to retype your
code to test any suggestions I may have. And you may have already had
to, so you may have introduced errors en route.
> 2 {
> 3 char ch;
> 4 int *p;
> 9 p = (int *)(&ch);
This casts a char* into an int*.
int* and char* are rather different pointer types. Converting one into
the other may not work but often will.
> 5 int *p2;
> 10 p2 = *(int **)(&ch);
This casts a char* into an int**, then dereferences it.
int** and char* are definitely different pointer types, converting one
into the other is almost certain to do strange things.
> 13 printf("%c", *p);
> 14 printf("%c", *p2); /* error in de-reference */
you won't get a compile error here provided you #include stdio.h
The result however may be garbage, or crash your application.
Mark McIntyre
--
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----