AHCC printf bug

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 5122
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

AHCC printf bug

Postby simonsunnyboy » Wed Nov 13, 2013 5:31 pm

While working on my fixed point math problem, I discovered some interesting printf behaviour by AHCC v4.15:

Code: Select all

#include <stdint.h>
#include <stdio.h>
#include <tos.h>


int main(int argc, char **argv)
{
   int32_t i;
   
   for(i = -100000; i < 100000; i = i + 10000)
   {
      printf(" Integer: %8d Hex: %8d\n",i,i);
   }

   Bconin(2);
   
   return 0;
}


and the project file:

Code: Select all

; 68020+ version using AHCC libraries

printf.tos
.C [-2]
.C [-iinclude]
=
ahcstart.o
printf.c
ahccstdi.lib


The result is in the attached screenshot from Hatari (and identical on my Falcon)

grab0001.png
You do not have the required permissions to view the files attached to this post.
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 808
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: AHCC printf bug

Postby mfro » Wed Nov 13, 2013 5:55 pm

No bug. Works as designed, I suppose.

You print - in an environment where a 16 bit number is supposed to be an int - a 32 bit number with "%d" (=int) format.

You get what you called for: the 16 bit remainder of the number. Change the format to "%ld" and you will probably get what you want.

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 5122
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: AHCC printf bug (no bug, just a feature)

Postby simonsunnyboy » Wed Nov 13, 2013 6:28 pm

Verified and another lesson learned...I obviously use the options not too often..and mostly on systems with 32bit ints where this would work as expected.
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 6 guests