Re: Weird malloc behaviour
- From: Barry Schwarz <schwarzb@xxxxxxxx>
- Date: Thu, 31 Jul 2008 11:29:17 -0700
On Thu, 31 Jul 2008 01:57:55 -0700 (PDT), leptone@xxxxxxxxx wrote:
Thank you for the suggestions, I will apply them in the "real
code" (this was just a test routine btw written in haste, although I
must admit that I still get quite brain damaged by type casting ;))...
The phrase "type casting" is like the phrase "over and out". Both
contain unnecessary words and indicate amateurish use. The operator
"(some_valid_C_type)" is a cast operator. No "type" required.
Casts are frequently overused and abused. The language is
sufficiently rich and flexible that they are not needed as often as
some think. But they are there for a reason and at times even
required. A few of the common correct uses of a cast are:
A printf argument corresponding to a %p format specification must
have type void*
A printf argument involving sizeof must be cast to the correct
type for the corresponding format specification. (In C99, the z
format modifier eliminates the need.)
To silence the diagnostic some compilers issue when
**deliberately** assigning an integer value to a variable of lower
rank or when **deliberately** demoting a floating point value.
When dereferencing the parameter of a callback function, such as
the compare function used by qsort. (In this case, some advocate
defining and initializing a local pointer of the correct type and
taking advantage of the implicit conversion between void* and other
object pointers.)
--
Remove del for email
.
- Follow-Ups:
- Re: Weird malloc behaviour
- From: Ben Bacarisse
- Re: Weird malloc behaviour
- References:
- Weird malloc behaviour
- From: leptone
- Re: Weird malloc behaviour
- From: Jens Thoms Toerring
- Re: Weird malloc behaviour
- From: Kenneth Brody
- Re: Weird malloc behaviour
- From: leptone
- Re: Weird malloc behaviour
- From: santosh
- Re: Weird malloc behaviour
- From: leptone
- Weird malloc behaviour
- Prev by Date: Re: A basic question question about volatile use
- Next by Date: Re: free()'ing restrict'ed pointers
- Previous by thread: Re: Weird malloc behaviour
- Next by thread: Re: Weird malloc behaviour
- Index(es):
Relevant Pages
|