From b468e3aae05d176dbb4b5cdc5820b80b1ed420b9 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 26 Nov 2016 02:54:25 +0100 Subject: Avoid warning in output code on 64-bit native Windows platforms. --- ChangeLog | 9 +++++++++ src/output.cc | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d1790de..0e5a9c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2016-11-26 Bruno Haible + + Avoid 'warning: cast from pointer to integer of different size' + in output code on 64-bit native Windows platforms. + * src/output.cc (output_keyword_entry): Cast pointer to 'size_t', + not to 'long', before casting it further to 'int'. + * tests/*.exp: Update. + Reported at . + 2016-11-26 Bruno Haible Don't use 'register' storage-class specifier in C++ output code. diff --git a/src/output.cc b/src/output.cc index c6eef39..1ec5d39 100644 --- a/src/output.cc +++ b/src/output.cc @@ -1169,7 +1169,20 @@ output_keyword_entry (KeywordExt *temp, int stringpool_index, const char *indent if (option[TYPE]) printf ("{"); if (option[SHAREDLIB]) - printf ("(int)(long)&((struct %s_t *)0)->%s_str%d", + /* How to determine a certain offset in stringpool at compile time? + - The standard way would be to use the 'offsetof' macro. But it is only + defined in , and is not among the prerequisite + header files that the user must #include. + - The next best way would be to take the address and cast to 'intptr_t' + or 'uintptr_t'. But these types are only defined in , and + is not among the prerequisite header files that the user + must #include. + - The next best approximation of 'uintptr_t' is 'size_t'. It is defined + in the prerequisite header . + - The types 'long' and 'unsigned long' do work as well, but on 64-bit + native Windows platforms, they don't have the same size as pointers + and therefore generate warnings. */ + printf ("(int)(size_t)&((struct %s_t *)0)->%s_str%d", option.get_stringpool_name (), option.get_stringpool_name (), stringpool_index); else -- cgit v1.2.1