From: Hyman Rosen <hyrosen@mail.com>
Subject: Re: ANN: New technical paper from Ada Europe 2004 now available
Date: Wed, 30 Jun 2004 12:16:28 -0400
Date: 2004-06-30T12:16:28-04:00 [thread overview]
Message-ID: <1088612188.693737@master.nyc.kbcfp.com> (raw)
In-Reply-To: <cf2c6063.0406300646.49f0848c@posting.google.com>
Rod Chapman wrote:
> "High-Integrity Ada in a UML and C World", Peter Amey and Neil White
The automatically generated C in this paper contains
typedef Colour_ADT_RGB_Value Colour_ADT_Colour[3];
void Colour_ADT_SWAP(Colour_ADT_Colour *A, Colour_ADT_Colour *B)
{
Colour_ADT_Colour Temp;
memmove((void*)Temp,(void*)A,6);
memmove((void*)A,(void*)B,6);
memmove((void*)B,(void*)Temp,6);
}
Those memmoves exhibit bad C style.
First of all, the casts to void * are unnecessary; in C any pointer
converts automatically to void * and no cast is needed.
Second, coding an explicit 6 for the memmove size is bad practice.
It would make the code unportable to funny architectures such as
some DSPs where the compiler has sizeof(int) = 1.
Third, memmove guarantees that copies of overlapping objects work;
for this case, the more efficient memcpy is better, because there is
no possibility of overlap.
Fourth, the parameters are pointers to arrays, so it's more coherent
stylistically to pass &Temp to the copy function rather than plain
Temp, even though the effect is the same.
It would be much nicer for the code to read
memcpy(&Temp, A, sizeof(Colour_ADT_Colour));
memcpy(A, B, sizeof(Colour_ADT_Colour));
memcpy(B, &Temp, sizeof(Colour_ADT_Colour));
next prev parent reply other threads:[~2004-06-30 16:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-30 14:46 ANN: New technical paper from Ada Europe 2004 now available Rod Chapman
2004-06-30 16:16 ` Hyman Rosen [this message]
2004-07-01 15:04 ` Mike Silva
2004-07-01 15:59 ` Hyman Rosen
2004-07-02 10:31 ` Peter Amey
2004-07-02 13:33 ` Hyman Rosen
2004-07-02 18:45 ` Wes Groleau
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox