housel@ea.ecn.purdue.edu (Peter S. Housel) (10/20/87)
Problem: On machines with a non-Vax-byteorder, the pascal compiler (pc) attempts to realign small structures when they are passed by value. Unfortunately, this realignment only happens in the called procedure and not in the function call, so accesses to fields within the structure get the wrong bytes. Repeat-By: Run the following program. It fails (prints two different values) on some machines with big-endian byteorder, such as the Gould 9080 or CCI 6/32. It does not fail on a Sun, but we don't have Sun pascal source so I can't tell why. -----------------cut-------------------- program pgm(output); type foo = record bar:1..10 end; var pos : foo; procedure killer(arg : foo); begin writeln('arg=',arg.bar) end; begin pos.bar := 2; writeln('pos=', pos.bar); killer(pos); end. -----------------cut-------------------- Fix: Apply the following patch to /usr/src/ucb/pascal/src/fhdr.c, BY HAND. This diff is relative to the VAX version, which obviously doesn't have the problem. *** fhdr.c.old Mon Oct 19 17:43:22 1987 --- fhdr.c Mon Oct 19 17:44:50 1987 *************** *** 383,393 **** # ifdef PC o = roundup(o, (long) A_STACK); w = lwidth(p); ! # ifndef DEC11 if (w <= sizeof(int)) { o += sizeof(int) - w; } ! # endif not DEC11 dp = defnl((char *) idlist->list_node.list,VAR, p, o); o += w; --- 383,393 ---- # ifdef PC o = roundup(o, (long) A_STACK); w = lwidth(p); ! # ifdef vax if (w <= sizeof(int)) { o += sizeof(int) - w; } ! # endif vax dp = defnl((char *) idlist->list_node.list,VAR, p, o); o += w; ---------------------- Peter S. Housel housel@ei.ecn.purdue.edu {decvax,uiucdcs,inuxc}!pur-ee!housel