Path: chuka.playstation.co.uk!news From: "Craig Graham" Newsgroups: scee.yaroze.programming.3d_graphics Subject: Re: GsLinkObject4 prototype error? Date: 11 Aug 1998 16:17:41 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 53 Message-ID: <01bdc542$ea168620$230b0a0a@Angela1.intelligent-group.com> References: <35CF88D3.4762@manc.u-net.com> <35CFA154.5EAB@manc.u-net.com> <35D03B22.5D50@manc.u-net.com> <35D05070.348AE2E@scee.sony.co.uk> NNTP-Posting-Host: 194.131.235.3 X-Newsreader: Microsoft Internet News 4.70.1155 James Russell wrote in article <35D05070.348AE2E@scee.sony.co.uk>... > James Shaughnessy wrote: > > > > Turns out that passsing a u_long to GsLinkObject4 compiles fine > > but crashes the program. > > It shouldn't. GsLinkObject4 definitely needs a u_long, but internally converts it to a u_long*. > Instead of changing libps.h, it might be an idea to cast it properly: > > u_long *memaddress = (u_long *)0x80091234; > GsLinkObject4((u_long)(memaddress + 3), .... Don't do that. What was happening is: GsLinkObject4((u_long*)memaddress + 3, ..) cast's memaddr to a u_long*, then adds sizeof(u_long)*3 to it (check your pointer addition semantics), so you get the cast warning in the compiler, but it does work. Actual value passed will be memaddr+sizeof(u_long)*3==&memaddress[3]==valid address Doing what James suggests will indeed cause a crash as you then get the actual value passed as: memaddr+3==an odd address==a crash like it says below. > Because of your change to libps.h, the compiler will think that it is passing a pointer instead of > an integer. I can't think of any reason why, but it might just change the code output by the > compiler. (Actually, I checked - with my compiler, it doesn't, but GNU might). It's more likely that > you've done something like added 3 to a u_long, which will create an unaligned address, crashing the > system. To ditch all the errors use: GsLinkObject4((u_long)memaddress + (u_long)(sizeof(u_long)*3),...) or GsLinkObject4((u_long)((u_long*)memaddress + 3),...) > Cheers, > > James Craig.