X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com Message-ID: <5305FF1A.4010804@Damon-Family.org> Date: Thu, 20 Feb 2014 08:11:54 -0500 From: Richard Damon User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Re: DJGPP gcc 4.7.3 and 4.8.2 work inconsistently on type uint32_t. References: <61118811-548e-4c11-8d04-e73de3c7da86 AT googlegroups DOT com> In-Reply-To: <61118811-548e-4c11-8d04-e73de3c7da86@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:RZtC7RBuhQWdSD50ASKQd+ZkkjtS4ob2Cyy4wPqtkXn Y8HGbIHR6M50H+iAPNWSJzIwmUqak5wolzoP1XWIMt96R1bsru NFqE0oFLsw57amLyXKb5UlvBRmOaWX5kBE+jntqhU91FqhnhLD Ice4eeX4FdM9c47N2Wx8EjLT9v3yNlgQz29pRYO4NX5Lt2eniT dypNmFEli5Kd6/qb6KLHNj4RdPjk+qQTvVNm6inJUBaW8H1JlC nYltcUkTs/yvOkncpwOB1Lko02rkMOH1AepzXWI5YKeToPHefR heabIaVS5S2Lt0+J+cqj0kHpnPurMGc+08qwxSb9l7m4+2cLvu FHCEXjO1U0po3bsfvHMlw8ssmtzWgssf72fgYeeHK Reply-To: djgpp AT delorie DOT com On 2/20/14, 4:27 AM, Andrew Wu wrote: > Hello, > > I found that for type uint32_t, DJGPP gcc 4.7.3 and DJGPP gcc 4.8.2 work inconsistently. > > File x.c: > > ==== > #include > #include > int main() > { > uint32_t x = 100; > printf("Hello %x \n", x); > return 0; > } > ==== > > Compile the file with "-Wall" to enable all warnings. > > gcc -Wall -c x.c > > If I uses DJGPP gcc 4.7.3, there is no problem. > > But if I use DJGPP gcc 4.8.2, there will be warning message: > > > x.c: In function 'main': > x.c:6:3: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'uint32_t' [-Wformat=] > printf("Hello %x \n", x); > ^ > > DJGPP gcc 4.7.3 binary files are from the official DJGPP Zip File Picker : > > http://www.delorie.com/djgpp/zip-picker.html > > I download and use: > > bnu224b.zip > djdev203.zip > gcc473b.zip > > Other files are not important, so I ignored them. > > DJGPP gcc 4.8.2 binary files are downloaded from official FTP's beta directory : > > ftp://ftp.delorie.com/pub/djgpp/beta/ > > I download and use: > > bnu224b.zip > djdev204.zip > gcc482b.zip > > It seems uint32_t type definition is changed between gcc 4.7.3 and 4.8.2? > The problem is that by the standard, %x requires a parameter of type (unsigned) int, and uint32_t may or may not be of that type. Printing a uint32_t with a %x format is really a BUG in the program (or at the very minimum, a dependance on unpromised implementation defined behavior, which is really just a polite name for bug. I will admit that it is a common error for people who grew up on 32 bit machines, as for them int has always been 32 bits, so things always just worked (even if performing technically undefined behavior if the implementation decided that uint32_t should be a unsigned long (which also is 32 bits on most 32 bit machines). If you want to print out a uint32_t, you should include and use the macro PRIx32as in printf("Hello %" PRIx32 " \n", x); -- Richard Damon