Wednesday, August 24, 2005

Don't foreget when you define a pointer to define what it points to !
struct mystuct * s;
You can't say s->v1 = ... ; as you didn't say s equals what !!
you 've to say first s = new pointer, or s = return of a function ...

Don't forget to deallocate memory of a pointer received from a function return. (you didn't allocate that memory but it was allocated by the function you called)

Note That:
In a function, you have to return an allocated pointer (or edit a pointer passed to it as an argument) and you CANNOT return address of an object, cuz the object is locally defined and will be destroyed at the function termination, so the address will be pointing to garbage.

Also, it is NOT RECOMMENDED to pass solid objects through functions, especially if they are large size objects or structures as it is overhead on the stack

No comments:

Post a Comment