Re: Thank You -- Thomas J. Gritzan
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Tue, 12 Sep 2006 17:20:40 -0400
Tom wrote:
.... snip ...
The following is a MS example that FAILS to compile:
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
void main( void )
{
long *buffer;
size_t size;
if( (buffer = (long *)malloc( 1000 * sizeof( long ) )) == NULL )
exit( 1 );
size = _msize( buffer );
printf( "Size of block after malloc of 1000 longs: %u\n", size );
/* Reallocate and show new size: */
if( (buffer = realloc( buffer, size + (1000 * sizeof( long )) ))
== NULL )
exit( 1 );
size = _msize( buffer );
printf( "Size of block after realloc of 1000 more longs: %u\n",
size );
free( buffer );
exit( 0 );
}
=============================
Here's the compiler error:
Compiling...
main.cpp
c:\stock programs\temp project tbd\main.cpp(40) : error C2440: '=' :
cannot convert from 'void *' to 'long *'
Conversion from 'void*' to pointer to non-'void' requires an
explicit cast
Error executing cl.exe.
temp project tbd.exe - 1 error(s), 0 warning(s)
=============================
Someone did not even take the effort to compile their own example!!
Add the cast and it works.
You are using a C++ compiler. Don't do that. I don't know just
how you control the MS monstrosity, but look to the IDE setup
and/or the source file naming. The file extension should be
lowercase .c, not .cpp.
--
"I was born lazy. I am no lazier now than I was forty years
ago, but that is because I reached the limit forty years ago.
You can't go beyond possibility." -- Mark Twain
--
Posted via a free Usenet account from http://www.teranews.com
.
- Follow-Ups:
- Re: Thank You -- Thomas J. Gritzan
- From: Richard Heathfield
- Re: Thank You -- Thomas J. Gritzan
- References:
- Thank You -- Thomas J. Gritzan
- From: Tom
- Re: Thank You -- Thomas J. Gritzan
- From: Richard Heathfield
- Re: Thank You -- Thomas J. Gritzan
- From: Tom
- Thank You -- Thomas J. Gritzan
- Prev by Date: Re: Smart Pointers: Is there something similar to smart pointers in C?
- Next by Date: Re: I've problem with my file handling program. See this
- Previous by thread: Re: Thank You -- Thomas J. Gritzan
- Next by thread: Re: Thank You -- Thomas J. Gritzan
- Index(es):
Relevant Pages
|