buf = (char*)GlobalAlloc(GPTR, len + 1);
what does (char*) mean? does that mean return a char pointer?
buf = (char*)GlobalAlloc(GPTR, len + 1);
what does (char*) mean? does that mean return a char pointer?
It is called type-casting , it means that you want an object of a particular type to be interpreted as some other type without getting warnings or errors from the compiler.
The one who says it cannot be done should never interrupt the one who is doing it.
Thanks
but type-casting syntax of C is different from C++ ?
>but type-casting syntax of C is different from C++ ?
No, the syntax is the same. Anything between ( and ) prefixing a variable or a constant is 'Type Casting'
Last edited by shaik786; 07-07-2002 at 03:48 AM.
is that mean by using (), we can change any type variable to any type variable ?
>is that mean by using (), we can change any type variable to any type variable?
More or less. C offers a lot of freedom in casting, but don't expect your casts to always work as you expect. In my opinion, casts are usually a crutch for bad design and I try to only use them to clear Lint warnings when it's safe, such as:
(void)puts ( "The void cast removes an annoying warning );
-Prelude
My best code is written with the delete key.
>> is that mean by using (), we can change any type variable to any type variable?
By using casts, we can "coerce the compiler into thinking that a variable or constant is a different type from the one that you declared it to be or, as in the case of an expression, a different type than the one implied by its context. For that, you use a cast, which has this format :
int *iptr = (int*) &table;
These are the best uses of the cast - to suppress compiler warnings about thing that you do intentionally. Using the cast to override the compiler's limited type-checking facilities is a bad practice." - Al-Stevens Teaches C (BPB Publications)