#52 HUGE bug (are you guys blind?)

closed-out-of-date
compiler (25)
5
2001-11-05
2000-10-05
Anonymous
No

Hi y'all!
I don't know if any of you have ever tested the following HUGE LARGE COMPLEX
ULTRA LONG program on ANY version of GBDK, but it's buggy. Check it out;

#include <stdio.h>

main()
{
unsigned char i = 7;
printf("%d", i);
return 0;
}

why does this code print something like '9898' or '-21454' instead of '7'?
Try the following:

#include <stdio.h>
main()
{
UBYTE i;
i = 200;
while(i--)
printf("%d",i);
}

It prints stuff like '-140' and shit.
Why is this?
It's not the variable that's screwed up, it's printf(), offcourse.
Check it out and fix it, cos it's a pain in the ass for debugging.

-MTS

Discussion

  • Nobody/Anonymous

    Because %d refers to a SIGNED value, dumb-dumb. If you are using an unsigned char, use %u
    Shit like this is the direct result of people who do not know how to code jumping immediately into the gameboy coding arena.

     
  • Nobody/Anonymous

    I believe that your example is wrong.

    The format statement in printf specifies %d which presumes that that the next argument is an int rather than an singed char. I don't believe that chars will get promoted to ints in this case because the printf prototype can't specify the argument type. I would expect the following to function properly.

    signed char;
    printf("%d", (int)i);

    or
    int i
    printf("%d", i);

     
  • Michael Hope

    Michael Hope - 2001-11-05
    • assigned_to: nobody --> michaelh
    • status: open --> closed-out-of-date
     
  • Michael Hope

    Michael Hope - 2001-11-05

    Logged In: YES
    user_id=373

    This is a canned message in response to all of the pre 2.96 open
    bugs. Could you please try and reproduce this under 2.96? gbdk
    2.96 is available from the gbdk download page or from
    http://gbdk.sourceforge.net/staging.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks