[ADMB Users] How to use Autodif as a regular external C++ library?
Pedro Tabacof
tabacof at gmail.com
Sun Nov 4 17:41:57 PST 2012
Dave, thanks a lot for your help. Indeed it was necessary to use new and
delete instead of malloc, now my code is working just as I intended (in the
end I used only classes to make the code more elegant). May I ask you two
more questions? They are not essential but nonetheless important for a
better code.
1) What do you think is the best way to read a dvariable value from a file,
if the value has been stored as a double? Right now I'm reading it to a
regular double variable and then casting it to a dvariable.
2) This has been puzzling me: sizeof(dvariable) return 4, while
sizeof(double) returns 8, why is dvariable size smaller than double?
Pedro.
On Sun, Nov 4, 2012 at 10:02 PM, dave fournier <davef at otter-rsch.com> wrote:
>
> I was curious to see if you needed to change struct to class.
> It appears not. But you do need to use new and delete
> as this simple example shows.
>
>
> #include <fvar.hpp>
>
> struct mys
> {
> dvariable x;
> };
>
> main()
> {
> gradient_structure gs(1000000);
>
> // this will work
> mys u;
> u.x=5;
> cout << u.x << endl;
>
> // this will work
> mys * pu2 = new mys;
> pu2->x=7;
> cout << pu2->x << endl;
> delete pu2;
> pu2=0;
>
> // this will crash
> mys * pu=(mys*) malloc(sizeof(mys));
> pu->x=6;
> cout << pu->x << endl;
>
> }
>
> ______________________________**_________________
> Users mailing list
> Users at admb-project.org
> http://lists.admb-project.org/**mailman/listinfo/users<http://lists.admb-project.org/mailman/listinfo/users>
>
--
Pedro Tabacof,
Unicamp - Eng. de Computação 08.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/users/attachments/20121104/57e1a967/attachment.html>
More information about the Users
mailing list