到底是不是MSDN错了?
请看下面一段MCSN中的例子:/* MALLOC.C: This program allocates memory with
* malloc, then frees the memory with free.
*/
#include <stdlib.h> /* For _MAX_PATH definition */
#include <stdio.h>
#include <malloc.h>
void main( void )
{
char *string;
/* Allocate space for a path name */
string = malloc( _MAX_PATH );
if( string == NULL )
printf( "Insufficient memory available\n" );
else
{
printf( "Memory space allocated for path name\n" );
free( string );
printf( "Memory freed\n" );
}
}
以上一段代码在VC6.0中无法编译通过,应该为:
/* MALLOC.C: This program allocates memory with
* malloc, then frees the memory with free.
*/
#include <stdlib.h> /* For _MAX_PATH definition */
#include <stdio.h>
#include <malloc.h>
void main( void )
{
char *string;
/* Allocate space for a path name */
string =(char*) malloc( _MAX_PATH );
if( string == NULL )
printf( "Insufficient memory available\n" );
else
{
printf( "Memory space allocated for path name\n" );
free( string );
printf( "Memory freed\n" );
}
}
只有这样才对。
到底是不是MSDN错了?