structure alignment question

karl at haddock karl at haddock
Mon Sep 22 23:15:00 AEST 1986


>In article <1705 at mcc-pp.UUCP> tiemann at mcc-pp.UUCP (Michael Tiemann) writes:
>>The last 68000 compiler I used aligned strings on WORD boundaries. ...
>>There was a big speed payoff: I could do word operations in [strncpy, etc.]

Wrong!  Even if strings are word-aligned, substrings (e.g. "p+1") will not
be.  (Unless the chars themselves are word-aligned, in which case your space
penalty is a factor of two instead of a half byte.)

umcp-cs!chris (Chris Torek) writes:
>It is not difficult to do copies in word mode iff the strings are aligned:
>[example of a strcpy() that considers four alignment cases]

Even if the strings are word-aligned, you have to test for a null *byte*
(not a zero word); my guess is that the extra manipulation inside the loop
will make it slower than a byte-by-byte copy.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list