[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [ProgSoc] New struct in C++



> -----Original Message-----
> From: owner-progsoc@xxxxxxxxxxxxxxxxxx [mailto:owner-
> progsoc@xxxxxxxxxxxxxxxxxx] On Behalf Of Matthew Beauregard
> Sent: Saturday, 16 October 2004 3:51 PM
> To: progsoc@xxxxxxxxxxxxxxxxxx
> Subject: [ProgSoc] New struct in C++
> 
> I hate to ask what should be a simple question, but in a C++ program
> I'm working on I have:
> 
>     gsl_odeiv_system sys = {func, jac, n.m_de.m_num_vars, &(n.m_de)};
>     n.m_sys = &sys;
> 
> This will not do because I need sys allocated onto the heap.  It'd be
> sufficient to do
> 
>     n.m_sys = {func, jac, n.m_de.m_num_vars, &(n.m_de)};
> 
> because n won't fall out of scope, but that statement won't compile.
> Everything I know about gsl_odeiv_system is at
> <http://www.lsw.uni-heidelberg.de/manuals/gsl-ref-html/gsl-
> ref_24.html#IDX1679>.
> I suppose it must be a struct because GSL is a C library, but I don't
> know what the member names are so I can't initialise it in pieces.
> What's the solution?

From that website, it appears that the member names are 'function',
'jacobian', 'dimension' and 'params'. Can you check the header file?

What is the (compiler/runtime) errors that you get with the first and second
forms?

Do you mean heap or stack? If you mean heap, then you actually need (in C):

gsl_odeiv_system *sys = NULL;

sys = malloc (sizeof(gsl_odeiv_system));
sys->function = func;
sys->jacobian = jac;
sys->dimension = n.m_de.m_num_vars;
sys->params = &n.m_de;

/* Do something with the system of equations */

free (sys);


Another alternative might be:



gsl_odeiv_system sys1 = {func, jac, n.m_de.m_num_vars, &n.m_de};
gsl_odeiv_system *sys = NULL;

sys = malloc (sizeof(gsl_odeiv_system));
*sys = sys1;

/* Do something again... */

free (sys);



Nigel

--
Nigel Sheridan-Smith
PhD research student

Faculty of Engineering
University of Technology, Sydney
Phone: 02 9514 7946
Fax: 02 9514 2435


> 
> thanks,
> 
> --
> `The trouble with you, Ibid,' he said, `is that you think you're the
> biggest bloody authority on everything.'
>    - Terry Pratchett, ``Pyramids''
> ~
> Matthew Beauregard
> Faculty of Information Technology, UTS
> Rm 10/03.420
> 9514 4447
> 
> 
> -
> You are subscribed to the progsoc mailing list. To unsubscribe, send a
> message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
> If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help.



-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help.