Mary_Kay_Anderson@UB.CC.UMICH.EDU (04/12/90)
What's wrong with this picture, or what's wrong with this
cc compiler? The following dumps core at *lp=5:
char buf[1024];
main()
{
long *lp;
int i;
lp = (long *)&buf[6];
*lp = 5;
printf("%ld\n", *lp);
}
However.... If you replace the &buf[6] with &buf[0], it
works the way you would expect and prints 5 to the screen.
Looks like a bug?
Thanks for any help you can give me.
Tim Buxton
OptiMetrics, Inc.
Tim_Buxton@um.cc.umich.edu
scotth@corp.sgi.com (Scott Henry) (04/12/90)
> What's wrong with this picture, or what's wrong with this > cc compiler? The following dumps core at *lp=5: > > char buf[1024]; > main() > > { > > long *lp; > > int i; > > > lp = (long *)&buf[6]; > > *lp = 5; > > printf("%ld\n", *lp); > > >} > > However.... If you replace the &buf[6] with &buf[0], it > works the way you would expect and prints 5 to the screen. > Looks like a bug? > Thanks for any help you can give me. This code came from and works on a VAX, right :-)? The MIPS processor can only access long data on long boundaries. Assuming that the buffer starts at a longword boundary, offsets that are on a longword boundary ([0], [4], [8], etc) will work, any other offset will cause a segv and core dump. If lp where a short, then offsets that are a multiple of a short (0, 2, 4, 6, etc) would work. (VAX's can access any sized data at any offset). Hope this helps! > Tim Buxton > OptiMetrics, Inc. > Tim_Buxton@um.cc.umich.edu -- Scott Henry <scotth@sgi.com> | Traveller on Dragon Wings Information Services, | Silicon Graphics, Inc | These are my Opinions only! Whose else?
msc@ramoth.esd.sgi.com (Mark Callow) (04/13/90)
In article <SCOTTH.90Apr12092017@harlie.corp.sgi.com>, scotth@corp.sgi.com (Scott Henry) writes: > [8], etc) will work, any other offset will cause a segv and core dump. If Actually it causes a bus error (SIGBUS) not a segmentation violation (SIGSEGV). -- From the TARDIS of Mark Callow msc@ramoth.sgi.com, ...{ames,decwrl}!sgi!msc "There is much virtue in a window. It is to a human being as a frame is to a painting, as a proscenium to a play. It strongly defines its content."
lacey@contex.UUCP (Dan Lacey) (04/13/90)
There is undocumented ( in any normal sense ) switch to cc: -align8 Use this when you compile. We use this in general to avoid these problems. ===================================================================== | Dan "GO FOR IT" Lacey | "It never got weird enough." | | Senior Software Engineer | Dr. H.S.Thompson | | Xyvision Design Systems, Inc. | | | 101 Edgewater Drive | | | Wakefield, MA. 01880 | | | (617) 245-9004 X5575 | | | contex!lacey@uunet.uu.net | | =====================================================================