forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
ldqmoon



Joined: 04 Dec 2007
Posts: 13

PostPosted: Tue Jul 29, 2008 1:14 pm    Post subject: what's the meaning of this code from stdlib.c Reply with quote

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
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Tue Jul 29, 2008 1:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Tue Jul 29, 2008 2:19 pm    Post subject: Reply with quote

Misguided attempt? Are you sure it was me? :)
Back to top
View user's profile Send private message Visit poster's website
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Wed Jul 30, 2008 9:42 am    Post subject: Reply with quote

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
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Wed Jul 30, 2008 3:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu Jul 31, 2008 1:36 am    Post subject: Reply with quote

Crap. Now I look like a noob.

NOOB SAIBOT YEAH!!! FATALITY!!!
Back to top
View user's profile Send private message Visit poster's website
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu Jul 31, 2008 1:43 am    Post subject: Reply with quote

Fixed in ps2sdk now, too.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group