Re: Thank You -- Thomas J. Gritzan



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

.



Relevant Pages

  • Re: CFile and FILE*
    ... ever call exit() in any C++ ... LPVOID, e.g., ... void DoSomething ... Note that you can still compile this as C ...
    (microsoft.public.vc.mfc)
  • compiling c code in vs.net?
    ... I have some code write in c and I try to compile in vs .net 2003. ... void init_put_bits(PutBitContext *s, ... uint8_t *buffer, int buffer_size, ... How can fix this errors and it nop some problem, ...
    (microsoft.public.vsnet.general)
  • lide: linux ide, just concept idea (Re: coloring stdout && stderr, small kbuild example)
    ... stderr, no cut; stderr out is rare, thus full lines ... buffer; append current line ... $lideSYNTAX ... ' EXIT HUP INT TERM QUIT ...
    (Linux-Kernel)
  • Re: simple read char app return wrong value?
    ... We know that sys_read doesn't return until the user hits "enter" (We would prefer, perhaps, that it did. ... If we need to "flush" some, we read into a different buffer, one at a time, until we find the "enter" key. ... Rather than return the number of bytes read, I've modified the program to return (as an exit code) the character entered. ... mov ecx, the_char; input array ...
    (alt.lang.asm)
  • RE: Buffer Overflow problem
    ... HACK is stored at address 0xbffffa56 ... sh-2.05b# exit ... overflowing the vulnerable buffer, thereby placing ... to facilitate one-on-one interaction with one of our expert instructors. ...
    (Security-Basics)