Discussion:
src/winsup/utils ChangeLog.64bit cygcheck.cc l ...
Eric Blake
2013-02-06 17:36:05 UTC
Permalink
CVSROOT: /cvs/src
Module name: src
Branch: cygwin-64bit-branch
winsup/utils : ChangeLog.64bit cygcheck.cc ldd.cc locale.cc
mkgroup.c mkpasswd.c mount.cc passwd.c path.cc
ssp.c strace.cc tzset.c
* ssp.c: Disable entire functionality on x86_64 for now.
Out of curiosity, I looked at some of these changes.
http://sourceware.org/cgi-bin/cvsweb.cgi/src/winsup/utils/ldd.cc.diff?cvsroot=src&only_with_tag=cygwin-64bit-branch&r1=1.14&r2=1.14.2.1
#include <string.h>
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
#include <wchar.h>
#include <locale.h>
#include <sys/cygwin.h>
@@ -162,7 +164,8 @@
wchar_t *buf = get_module_filename (GetCurrentProcess (), NULL);
if (!buf)
{
- printf ("ldd: GetModuleFileName returned an error %lu\n",
GetLastError ());
+ printf ("ldd: GetModuleFileName returned an error %" PRIu32 "\n",
+ (unsigned int) GetLastError ());

PRIu32 is for uint32_t, not unsigned int; and on platforms where
uint32_t is unsigned long, you've ended up causing a compiler warning.
If you are going to cast GetLastError(), then just use %u; no need to
drag in <inttypes.h>.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Corinna Vinschen
2013-02-06 17:57:08 UTC
Permalink
Bzzz.
Post by Eric Blake
#include <string.h>
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
#include <wchar.h>
#include <locale.h>
#include <sys/cygwin.h>
@@ -162,7 +164,8 @@
wchar_t *buf = get_module_filename (GetCurrentProcess (), NULL);
if (!buf)
{
- printf ("ldd: GetModuleFileName returned an error %lu\n",
GetLastError ());
+ printf ("ldd: GetModuleFileName returned an error %" PRIu32 "\n",
+ (unsigned int) GetLastError ());
PRIu32 is for uint32_t, not unsigned int; and on platforms where
uint32_t is unsigned long, you've ended up causing a compiler warning.
If you are going to cast GetLastError(), then just use %u; no need to
drag in <inttypes.h>.
I changed that in ldd.cc. Other than that, We *know* that DWORD is
declared as unsigned long on 32 bit, but as unsigned int on 64 bit,
because sizeof long == 64 on x86_64-pc-cygwin. Therefore I'm using
the PRIu32 and PRIx32 to make sure that I have the right format
specifier for a known 32 bit variable, which uses a different type
on different platforms.


Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Eric Blake
2013-02-06 18:33:39 UTC
Permalink
Post by Corinna Vinschen
Post by Eric Blake
- printf ("ldd: GetModuleFileName returned an error %lu\n",
GetLastError ());
+ printf ("ldd: GetModuleFileName returned an error %" PRIu32 "\n",
+ (unsigned int) GetLastError ());
PRIu32 is for uint32_t, not unsigned int; and on platforms where
uint32_t is unsigned long, you've ended up causing a compiler warning.
If you are going to cast GetLastError(), then just use %u; no need to
drag in <inttypes.h>.
I changed that in ldd.cc. Other than that, We *know* that DWORD is
declared as unsigned long on 32 bit, but as unsigned int on 64 bit,
because sizeof long == 64 on x86_64-pc-cygwin. Therefore I'm using
the PRIu32 and PRIx32 to make sure that I have the right format
specifier for a known 32 bit variable, which uses a different type
on different platforms.
If DWORD were defined as uint32_t, then this would work without
questions. But because DWORD is defined as 'unsigned long' vs.
'unsigned int', rather than uint32_t, your trick of using PRIu32 will
only work if we also ensure that uint32_t is defined to the same type as
DWORD. I guess we could get away with that, but it is rather subtle.
If we go with that approach, then it would be sufficient to write:

printf("%" PRIu32 "\n", GetLastError ())

But if we are worried that DWORD and uint32_t can ever be defined
independently, then we risk mismatch between long and int on 32-bit
platforms, even though we know both types are 32-bits, and it is that
type mismatch that gcc warns about.

Anyways, thanks for the followup patch.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Loading...