delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/07/28/12:10:55

Date: Mon, 28 Jul 2003 18:47:01 +0200
From: "Eli Zaretskii" <eliz AT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp AT delorie DOT com
Message-Id: <7458-Mon28Jul2003184701+0300-eliz@elta.co.il>
X-Mailer: emacs 21.3.50 (via feedmail 8 I) and Blat ver 1.8.9
In-reply-to: <bg3d1h$d30$1@newsreader1.netway.at> (nospam@aol.com)
Subject: Re: integer overflow
References: <3F246120 DOT 63C3753C AT worldnet DOT att DOT net> <Z6_Ua.375$%S6 DOT 105 AT newsread1 DOT news DOT atl DOT earthlink DOT net> <3F24AA4B DOT 589D3482 AT worldnet DOT att DOT net> <bg3d1h$d30$1 AT newsreader1 DOT netway DOT at>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: "News Reader" <nospam AT aol DOT com>
> Newsgroups: comp.os.msdos.djgpp
> Date: Mon, 28 Jul 2003 16:44:36 +0200
> 
> According to my DJGPP documentation (C-library, HTML)
> the format string "%U" instead of "%lu" should work,
> but it doesn't.

How do you mean ``doesn't work''?  What exactly did you expect and
what did you see (a short test program and sample output would be
nice)?

Here's my test program:

#include <stdio.h>

int main (int argc, char *argv[])
{
  unsigned long k = argc * 3000000000LU;

  printf ("num: %U %ld\n", k, k);
  return 0;
}

and its output when invoked with no arguments (i.e. argc = 1):

  num: 3000000000 -1294967296

As you see, printing with %U succeeds while %ld tries to interpret the
unsigned value as signed and overflows.

The only problem with %U that I see is that it is non-standard, so
"gcc -Wall" rightfully complains about it.  But the program works
nonetheless.

- Raw text -


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