>Then you don't fully understand my point.
Allow me to take a stab at it. You are saying that the following code is wrong if I wanted to simulate an array of integers:
Code:
#include <stdlib.h>
/*
** my_header.h declares a to be a pointer to double
*/
#include "my_header.h"
int main ( void )
{
a = malloc ( 24 * sizeof *a );
return 0;
}
No warnings.
As it is the compiler implicitly converts the void pointer to a double pointer, the usage is correct, but not what you wanted. If, however, you had included a type cast to int * the compiler would likely give you a warning about incompatible types:
Code:
#include <stdlib.h>
/*
** my_header.h declares a to be a pointer to double
*/
#include "my_header.h"
int main ( void )
{
a = (int *)malloc ( 24 * sizeof *a );
return 0;
}
C:\C\C.c(9) : warning C4133: '=' : incompatible types - from 'int *' to 'double *'
This is a valid point, but so is the case for not using type casting. In the end, not using type casting is encouraged, but it is very largely a matter of style.
-Prelude