what's the meaning of this code from stdlib.c

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ldqmoon
Posts: 13
Joined: Tue Dec 04, 2007 1:17 am

what's the meaning of this code from stdlib.c

Post by ldqmoon »

Code: Select all

#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!
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

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()?
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

Misguided attempt? Are you sure it was me? :)
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

yes :)

Code: Select all

$ 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. :)

------------------------------------------------------------------------
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

Crap. Now I look like a noob.

NOOB SAIBOT YEAH!!! FATALITY!!!
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

Fixed in ps2sdk now, too.
Post Reply