Re: Weird malloc behaviour



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
.



Relevant Pages

  • [PULL] typesafe callbacks for kthread and stop_machine
    ... * because any other types will not be cast, they will cause a warning as ... the return type of the callback function ...
    (Linux-Kernel)
  • Re: using SetBitmap
    ... "hilla hartman" wrote in message ... > I wrote a program that is a dialog box and has a callback function. ... I suspect that GetDlgItem is returning an HWND... ... ...and cast that CWnd* to a CStatic*. ...
    (microsoft.public.vc.mfc)