delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/07/28/20:15:08

From: "News Reader" <nospam AT aol DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: integer overflow
Date: Tue, 29 Jul 2003 02:00:54 +0200
Organization: UTA/netway (Customer)
Lines: 65
Message-ID: <bg4dkh$8er$1@newsreader1.netway.at>
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> <7458-Mon28Jul2003184701+0300-eliz AT elta DOT co DOT il>
NNTP-Posting-Host: pat-ei.lucent.wellcom.at
X-Trace: newsreader1.netway.at 1059437009 8667 195.230.174.18 (29 Jul 2003 00:03:29 GMT)
X-Complaints-To: abuse AT netway DOT at
NNTP-Posting-Date: 29 Jul 2003 00:03:29 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Being human and therefore being prone to making mistakes
from time to time, I will not allow any of my programs to run
if the compiler output produces a single warning as a matter
of principle. "-Wall" has saved me (and my programs) several
times and this is the main reason why I still keep using C once
in a while.

Compilation of your code produces the following output:

   x.c: In function `main':
   x.c:7: warning: unknown conversion type character `U' in format
   x.c:7: warning: too many arguments for format

Therefore %U won't work (for me). The same applies to
%D and %O although even here program outputs appear
to be correct. (%I seems to be a different story, however.)

I am well aware of the differences between signed and unsigned,
thanks, I was just cutting into this thread to get the %U mystery
solved.

(Still wondering why %U was ever documented if it is non-standard
and produces warnings?)



"Eli Zaretskii" <eliz AT elta DOT co DOT il> wrote in message
news:7458-Mon28Jul2003184701+0300-eliz AT elta DOT co DOT il...
> > 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