delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/16/15:40:45

Date: Wed, 16 Jul 1997 12:38:45 -0700 (PDT)
Message-Id: <199707161938.MAA08174@adit.ap.net>
Mime-Version: 1.0
To: hubicka AT horac DOT ta DOT jcu DOT cz
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: long double and printf
Cc: djgpp AT delorie DOT com

I posted this before but I think it got lost in transit.
Jan Hubicka wrote:
>Hi
>I need to save/restore long doubles from file in as standard way as possible.
>Under linux I use printf("%LG"... and scanf("$LG...
>But under djgpp scanf seems to be broken.

I investigated this and it appears to be a libc bug. When a capital letter
is used, _doscan_low changes "long" sizes to "long double" size and anything
else to "long". It fails to account for the possibility that it may already
be "long double".

To work around, use scanf("%Lg..."...). Also included here is a patch which
fixes the bug. I do not, however, know whether it might break anything else.
Some input from the maintainer would be appreciated.

Patch to apply to src/libc/ansi/stdio/doscan.c
--cut--
*** olddosca.c	Sat May 18 21:40:02 1996
--- doscan.c	Mon Jul 14 12:01:54 1997
***************
*** 100,104 ****
        if (size==LONG)
          size = LONGDOUBLE;
!       else
          size = LONG;
      }
--- 100,104 ----
        if (size==LONG)
          size = LONGDOUBLE;
!       else if (size != LONGDOUBLE)
          size = LONG;
      }
--cut--

HTH

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019