delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/03/15/00:44:08

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_83,RCVD_IN_DNSWL_LOW,SPF_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <49BC958D.2080306@cwilson.fastmail.fm>
Date: Sun, 15 Mar 2009 01:43:41 -0400
From: Charles Wilson <cygwin AT cwilson DOT fastmail DOT fm>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.19) Gecko/20081209 Thunderbird/2.0.0.19 Mnenhy/0.7.6.666
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: long unsigned int vs. uint32_t again
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Why does the following give me a warning (with -Wformat=2):

      uint32_t seconds = ...
      uint32_t minutes = ...
      uint32_t hours   = ...
      snprintf(buf, sizeof(buf),
               "%" PRIu32 ":%02" PRIu32 ":%02" PRIu32,
               hours, minutes, seconds);

warning: long unsigned int format, uint32_t arg (arg 4)
                                                    warning: long
unsigned int format, uint32_t arg (arg 5)
                                  warning: long unsigned int format,
uint32_t arg (arg 6)

If you've got a uint32_t, then 'PRIu32' is the correct code to use,
right? What OTHER code could there be for printing unsigned, 32bit,
integers?

cygwin's <inttypes.h> has:
#define PRIu8 "u"
#define PRIu16 "u"
#define PRIu32 "lu"
#define PRIu64 "llu"

and <stdint.h> has
typedef unsigned int uint32_t;

This is on cygwin-1.7.0-43, with gcc-3.4.4-999.  Is it possible that our
inttypes.h should be changed, to use "u" for 8, 16, and 32 bits?  Or is
gcc's -Wformat=2 in 3.4.4 just too strict here -- and should be checking
the actual bitwidths of types against the formats, before assuming that
"lu" doesn't match uint32_t?

--
Chuck

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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