delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2005/01/08/05:17:29

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Date: Sat, 08 Jan 2005 12:14:03 +0200
From: "Eli Zaretskii" <eliz AT gnu DOT org>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp AT delorie DOT com
Message-ID: <01c4f56a$Blat.v2.2.2$ecce5460@zahav.net.il>
X-Mailer: emacs 21.3.50 (via feedmail 8 I) and Blat ver 2.2.2
In-reply-to: <NsLDd.54447$nP1.27785@twister.socal.rr.com>
(sam124 AT operamail DOT com)
Subject: Re: Strange problems with printf()
References: <NsLDd.54447$nP1 DOT 27785 AT twister DOT socal DOT rr DOT com>
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: "Samuel Lauber" <sam124 AT operamail DOT com>
> Date: Sat, 08 Jan 2005 06:54:37 GMT
> 
> int printf(char *, ...);
> int main(void)
> {
>      printf("%f\n", 1);
> }
> 
> Compile it, and it would say `Unnormal'. Is this a bug?

A bug, yes, but in your program, not in the compiler or the library.
If you compile with the -Wall switch, which prints warnings for
dubious code, the compiler says:

    cfp.c: In function `main':
    cfp.c:4: warning: double format, different type arg (arg 2)
    cfp.c:5: warning: control reaches end of non-void function

The first warning is directly related to what you see: you should use

     printf("%f\n", 1.0);

i.e. make the argument be a float or a double, not an int.

The second warning says that you should end this program with

     return 0;

since `main' is declared a function that returns an int.

- Raw text -


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