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
C99 Question
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Ben Pfaff, post: 1694435"] There are several situations where a cast legitimately comes in handy: * Conversion of one type's range to another's, as in the argument to the <ctype.h> to*() and is*() functions: isupper((unsigned char) c) * Conversion of an integer to a floating-point type for use in arithmetic. (Sure, you can assign it to a variable or multiply it by 1.0, but a cast can sometimes clarify what you're doing.) * Converting a pointer to the first member of a structure to a pointer to the structure, or a pointer to a member of a union to a pointer to the union. * Converting an lvalue to an rvalue for use in macros that can be used for access to objects but should not be used to modify those objects. (The unary plus operator is an alternative.) * Casting between different pointer-to-character types for, e.g., passing a unsigned char array to strcpy(). (You can avoid it by using a void * pointer variable as an intermediary, but that's hardly an improvement.) * Silencing compiler warnings about `comparing signed and unsigned types' ;-( * Passing a null pointer to a varargs function. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
C99 Question
Top