On 10/14/10 5:32 AM, Steffen Neumann wrote:
> Hi
>
> On Thu, 2010-10-14 at 11:56 +0100, Noel O'Boyle wrote:
>> memcpy((char*)origCoords,(char*)_mol.GetCoordinates(),sizeof(double)*_ncoords);
>>
>> However, both origCorrds and _mol.GetCoordinates are (double*) not
>> (char*). Is this not an error?
> No, a pointer has X bytes regardless whether it points
> to a char, double (or void :-)
>
> An it will copy _ncoords times the space required for sizeof(double).
> The error would be if it used sizeof(char).

Right, but ...

This is not a very good way to do this.  It assumes that _mol.GetCoordinates() 
is going to return an array of double exactly _ncoords long.  If someone 
changes the data structures, how would they know to look here to find this and 
fix it too?   It's a time bomb, especially if there is a lot of this sort of 
thing around.

The real question is whether the code ensures that origCoords was allocated to 
be at least as large as sizeof(double)*_ncoords.

This is an example of using C coding style in a C++ program.  The proper way to 
do it would be to create object classes so that you could just use a 
constructor or '=' operator to copy the coordinates.

Craig

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel

Reply via email to