
A suggestion for an easy way to fix this problem: use float instead of long. Presumably floats are always 4 bytes. Rick Paul Dubois writes:

I think a more portable solution is to just make it all an if statement. I'm not comfortable with presuming that floats are always 4 bytes. if (src_nd == 0 && dest_nd == 0) { if (elsize == sizeof(char)) { memset(dest, *src, copies); } else if (elsize == sizeof(short)) { for(j=copies; j; --j, dest += sizeof(short)) *(short*)dest = *(short*)src; } else if (elsize == sizeof(int)) { for(j=copies; j; --j, dest += sizeof(int)) *(int*)dest = *(int*)src; } else if (elsize == sizeof(long)) { for(j=copies; j; --j, dest += sizeof(long)) *(long*)dest = *(long*)src; } else if (elsize == sizeof(float)) { for(j=copies; j; --j, dest += sizeof(float)) *(float*)dest = *(float*)src; } else if (elsize == sizeof(double)) { for(j=copies; j; --j, dest += sizeof(double)) *(double*)dest = *(double*)src; } else { for(j=copies; j; --j, dest += elsize) memcpy(dest, src, elsize); } I've thrown in the int and float cases to make sure we cover every machine that may be out there. Lee Taylor On Wed, 6 Dec 2000 rlw@stsci.edu wrote:

I think a more portable solution is to just make it all an if statement. I'm not comfortable with presuming that floats are always 4 bytes. if (src_nd == 0 && dest_nd == 0) { if (elsize == sizeof(char)) { memset(dest, *src, copies); } else if (elsize == sizeof(short)) { for(j=copies; j; --j, dest += sizeof(short)) *(short*)dest = *(short*)src; } else if (elsize == sizeof(int)) { for(j=copies; j; --j, dest += sizeof(int)) *(int*)dest = *(int*)src; } else if (elsize == sizeof(long)) { for(j=copies; j; --j, dest += sizeof(long)) *(long*)dest = *(long*)src; } else if (elsize == sizeof(float)) { for(j=copies; j; --j, dest += sizeof(float)) *(float*)dest = *(float*)src; } else if (elsize == sizeof(double)) { for(j=copies; j; --j, dest += sizeof(double)) *(double*)dest = *(double*)src; } else { for(j=copies; j; --j, dest += elsize) memcpy(dest, src, elsize); } I've thrown in the int and float cases to make sure we cover every machine that may be out there. Lee Taylor On Wed, 6 Dec 2000 rlw@stsci.edu wrote:
participants (2)
-
Lee Taylor
-
rlw@stsci.edu