i****d 发帖数: 255 | 1 I have been using Fortran for many years but have to switch to C for the
current project. Get a question about structure initialization and would
appreciate any help!
I define a structure contatining a number of integers, reals, chars, and
arrays to be allocated. A point to such a structure is declared in the
main function, and I want to use a function to initialize this structure.
I know there must something wrong with my initialization function, but I
am unable to locate it. Many tutorials and | t****t 发帖数: 6806 | 2 1. you have to allocate memory for mygem, and have to do it in main (
otherwise the allocated address can't be passed back per your function
signature)
2. you don't have to allocate memory for array (mygem->quad). you do have to
allocate memory for pointer (mygem->vertex). | i****d 发帖数: 255 | 3 Thank you for the answer!
This is interesting. So I only can allocate memory for mygem in main!
Is there any other mean to do this sort of dynamical allocation?
to
【在 t****t 的大作中提到】 : 1. you have to allocate memory for mygem, and have to do it in main ( : otherwise the allocated address can't be passed back per your function : signature) : 2. you don't have to allocate memory for array (mygem->quad). you do have to : allocate memory for pointer (mygem->vertex).
|
|