Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Why is C compiler stubborn ?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Dave Vandervies, post: 2756792"] Nitpick: It's not strictly necessary to cast the pointer. You do need to make sure that it fgets converted to a void* through some mechanism, but if you already have an object of the correct type (void *) floating around with the suitably converted pointer value you want to print, you can just give printf the value of that object without casting it: -------- /*A bit verbose if you're not using vp anywhere else, but perfectly valid*/ void *vp=my_pointer_value; printf("%p\n",vp); /*leaks memory but otherwise correct*/ printf("%p\n",malloc(42)); /*Not quite incorrect, but gratuitiously wrong in several ways*/ printf("%p\n",(void *)(int *)malloc(sizeof(int))); -------- Giving non-void pointers to printf is, however, one of the few situations where pointer casts are all of correct, useful, and CLC-conforming. dave [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Why is C compiler stubborn ?
Top