Re: obj function hello()
- From: "gert" <gert.cuykens@xxxxxxxxx>
- Date: 9 Feb 2007 12:53:41 -0800
On Feb 9, 9:41 pm, Christopher Benson-Manica
<a...@xxxxxxxxxxxxxxxxxxx> wrote:
gert <gert.cuyk...@xxxxxxxxx> wrote:
I modified the example a bit to give it a more oo look but i still
having trouble understanding the memory allocation part ?
Obj* myobj = malloc(sizeof *myobj);
for me it would make more sense if i would wright
Obj* myobj = malloc(sizeof myobj);
Why? myobj is a *pointer* - you want enough memory for myobj to point
to an Obj, not however much memory the pointer takes up. This is a
crucial difference.
The thing is they both give the same output :)
Only because you seem to be lucky - the second version is wrong, and
either happens to allocate enough space for an Obj (implying
sizeof(Obj) < sizeof(Obj*)) or accesses memory it has no right to
access.
Ok i see, i have to allocate memory for myobj not the pointer it self
.
- References:
- obj function hello()
- From: gert
- Re: obj function hello()
- From: Ian Collins
- Re: obj function hello()
- From: gert
- Re: obj function hello()
- From: Ian Collins
- Re: obj function hello()
- From: gert
- Re: obj function hello()
- From: Ian Collins
- Re: obj function hello()
- From: gert
- Re: obj function hello()
- From: gert
- Re: obj function hello()
- From: Christopher Benson-Manica
- obj function hello()
- Prev by Date: Re: Horror! Using goto statement in finite state machines?
- Next by Date: Re: Horror! Using goto statement in finite state machines?
- Previous by thread: Re: obj function hello()
- Next by thread: Re: obj function hello()
- Index(es):
Relevant Pages
|