H
halfmaddad
Hi Everyone !
Could you confirm that the facts I am operating under are correct and help with a question I do not know the answer to?
Pointers sure are tricky and I am not sure I fully understand all the details.
is this correct?:
I know that pointers need to match the types of the items they point to butpointers are also just addresses and those are the same size(on the same machine) so the space that any pointer occupies ought to be the same.
Is this correct:
Do pointers need to match their type so that the compiler knows to reserve enough space for the pointed-to-item?
here is a bit of pseudo code:
massive_struct foo ;
foo = init_massive() ;
is this correct:
foo is a pointer, likely the same size as integer and it's pointing to an address and there are enough bytes after this address to accommodate all thedata for a massive_struct instance. The call to init_massive populates thefirst address and the bytes following it with various members, ints, function pointers etc.
Question, assuming that massive_struct took up 20 bytes of space would thiswork?:
I have barely touched memory management but if 20 bytes of memory were allocated and a pointer pointed to it, could the call to init_massive correctlypopulate that area of memory?
This doesn't make any sense in C but I am trying to figure out ways to store complex C structs for C bindings. If language X could allocate space for massive_struct and give that space a name, I am wondering if calls from init_massive could populate the space set aside by another language. The instance of that struct would then have a non-C variable name
Thanks for reading-Patrick
Could you confirm that the facts I am operating under are correct and help with a question I do not know the answer to?
Pointers sure are tricky and I am not sure I fully understand all the details.
is this correct?:
I know that pointers need to match the types of the items they point to butpointers are also just addresses and those are the same size(on the same machine) so the space that any pointer occupies ought to be the same.
Is this correct:
Do pointers need to match their type so that the compiler knows to reserve enough space for the pointed-to-item?
here is a bit of pseudo code:
massive_struct foo ;
foo = init_massive() ;
is this correct:
foo is a pointer, likely the same size as integer and it's pointing to an address and there are enough bytes after this address to accommodate all thedata for a massive_struct instance. The call to init_massive populates thefirst address and the bytes following it with various members, ints, function pointers etc.
Question, assuming that massive_struct took up 20 bytes of space would thiswork?:
I have barely touched memory management but if 20 bytes of memory were allocated and a pointer pointed to it, could the call to init_massive correctlypopulate that area of memory?
This doesn't make any sense in C but I am trying to figure out ways to store complex C structs for C bindings. If language X could allocate space for massive_struct and give that space a name, I am wondering if calls from init_massive could populate the space set aside by another language. The instance of that struct would then have a non-C variable name
Thanks for reading-Patrick