Re: allocating mem in a function and assigning a ptr to the first byte of that mem array...



mast2as@xxxxxxxxx wrote:

I almost apologize to ask this question but I have been starting at
this code for a bit of time and don't understand what's wrong with it.
I am not arguing about the fact it's good or not coding, it's actually
a shorter version of something more complex that i am doing.

Anway the idea is that there's a func Test which takes a pointer to
void argument, allocate some memory, set this memory with some cotent,
assign the ptr to a void to the first byte of this new alloc memory
and returuns. Normally because our argument points to the first byte
of that memory array * AND THAT THE MEM HASN'T BEEN FREED *, i should
still be able to access the content of that mem array.

But i don't it crashes.

Please help,

cheers -mark

#include <stdlib.h>
#include <stdio.h>
#include <cmath>

no such header file.


//#include <map>
#include <string>

no such header file.

If your compiler didn't object to the above, you are using a C++
compiler, which is not a good thing to do to C code.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>


.



Relevant Pages

  • Re: accessing memory addresses using C
    ... in emebdded world here) then I keep this address in a header file, ... typically in the private part of a class, ... If this is a memory ... It is undefined what is the unsigned char. ...
    (comp.dsp)
  • Re: Question to function code( ) :
    ... at the top of your program, or in a header file). ... let the client put 'infile' in read-only memory if he likes; ... idiomatic 'while' loop. ... Okay, so you also need to write 'decrypt'. ...
    (comp.lang.c)
  • Re: accessing memory addresses using C
    ... in emebdded world here) then I keep this address in a header file, ... size of the memory region in two different files, ... to be used by compiler or linker. ... The memset() is dangerous function with the platform dependent behavior. ...
    (comp.dsp)
  • Re: accessing memory addresses using C
    ... in emebdded world here) then I keep this address in a header file, ... typically in the private part of a class, ... If this is a memory mapped device, define it in the appropriate section. ... of those memory locations which are in fact device codes in ...
    (comp.dsp)
  • Re: Tracking the "memory growth" of a process
    ... > Here's the header file: ... otherwise de-allocating memory should cause the operating system to reclaim ... sure it's operating system dependent (and possibly implementation dependent ...
    (comp.lang.cpp)