| View previous topic :: View next topic |
| Author |
Message |
ldqmoon
Joined: 04 Dec 2007 Posts: 13
|
Posted: Tue Jul 29, 2008 1:14 pm Post subject: what's the meaning of this code from stdlib.c |
|
|
| Code: | #ifdef F_div
/*
**
** [func] - div.
** [desc] -
** [entr] - int n; the integer numerator.
** int d; the integer divisor.
** [exit] - div_t;
** [prec] - none.
** [post] - none.
**
*/ div_t div(int n, int d)
{
div_t ret;
/* calculate the quotient and remainder. */ // duh... can't this be written with some asm "mfhi/mflo" ?
ret.quot = (n / d);
ret.quot = (n % d);
ret.rem = 0; // set to 0 so it won't be uninitialized
return (ret);
}
#endif |
ret.quot = (n / d);
ret.quot = (n % d);
why it write like this ?
Thank you! |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Tue Jul 29, 2008 1:51 pm Post subject: |
|
|
it was a typo, and the "ret.rem = 0" line was a misguided attempt by ooPo to fix a compiler warning. i'll fix it now, although
- using psplibc isn't recommended
- does anyone actually use div()? |
|
| Back to top |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Tue Jul 29, 2008 2:19 pm Post subject: |
|
|
| Misguided attempt? Are you sure it was me? :) |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Wed Jul 30, 2008 9:42 am Post subject: |
|
|
yes :)
| Code: | $ svn blame -r{20080727} stdlib.c | grep -A 10 "div_t div"
23 tyranid div_t div(int n, int d)
23 tyranid {
23 tyranid div_t ret;
23 tyranid
23 tyranid /* calculate the quotient and remainder. */
23 tyranid // duh... can't this be written with some asm "mfhi/mflo" ?
23 tyranid ret.quot = (n / d);
23 tyranid ret.quot = (n % d);
176 oopo ret.rem = 0; // set to 0 so it won't be uninitialized
23 tyranid return (ret);
23 tyranid }
$ svn log -r176 stdlib.c
------------------------------------------------------------------------
r176 | oopo | 2005-06-14 15:08:24 -0400 (Tue, 14 Jun 2005) | 2 lines
Fixing various compiler warnings. There are very few compared to ps2sdk. :)
------------------------------------------------------------------------ |
|
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Wed Jul 30, 2008 3:19 pm Post subject: |
|
|
| I would like to point out that although my name is in that list of blame I just copied and pasted it from the ps2sdk, hehe :P |
|
| Back to top |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Thu Jul 31, 2008 1:36 am Post subject: |
|
|
Crap. Now I look like a noob.
NOOB SAIBOT YEAH!!! FATALITY!!! |
|
| Back to top |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Thu Jul 31, 2008 1:43 am Post subject: |
|
|
| Fixed in ps2sdk now, too. |
|
| Back to top |
|
 |
|