On 6/27/19 8:21 AM, Martin Liška wrote:
On 6/27/19 4:11 PM, Jakub Jelinek wrote:
On Thu, Jun 27, 2019 at 04:03:06PM +0200, Martin Liška wrote:
* ggc-page.c (free_page): Use (char *) for %p printf format
argument.
--- a/gcc/ggc-page.c
+++ b/gcc/ggc-page.c
@@ -977,7 +977,7 @@ free_page (page_entry *entry)
if (GGC_DEBUG_LEVEL >= 2)
fprintf (G.debug_file,
"Deallocating page at %p, data %p-%p\n", (void *) entry,
- entry->page, entry->page + entry->bytes - 1);
+ (char *)entry->page, (char *)entry->page + entry->bytes - 1);
/* Mark the page as inaccessible. Discard the handle to avoid handle
leak. */
Can you explain this? It makes no sense to me. What is the warning?
entry->page already has char * type, so why are any casts needed?
If you want to be pedantic, C says that %p argument should be pointer to
void, so I'd understand more
(void *) entry->page, (void *) (entry->page + entry->bytes - 1));
with that formatting.
You are right, it should be the other way around:
/home/marxin/Programming/gcc/gcc/ggc-page.c:946:60: warning: format specifies
type 'void *' but the argument has type 'char *' [-Wformat-pedantic]
I'm normally in favor of cleaning up warnings but this one looks
worse than useless to me: heeding it makes what's clean, easy t
read, and perfectly correct and safe code harder to read purely
for the sake of pedantry. There is no difference between a char*
and void*. If we want to make an improvement let's propose to
relax the pointless C requirement that the %p argument be a void*
and allow it to be any object pointer.
Martin
(void *) entry, (unsigned long) OBJECT_SIZE (order), page,
^~~~
/home/marxin/Programming/gcc/gcc/ggc-page.c:947:7: warning: format specifies
type 'void *' but the argument has type 'char *' [-Wformat-pedantic]
page + entry_size - 1);
^~~~~~~~~~~~~~~~~~~~~
/home/marxin/Programming/gcc/gcc/ggc-page.c:980:7: warning: format specifies
type 'void *' but the argument has type 'char *' [-Wformat-pedantic]
entry->page, entry->page + entry->bytes - 1);
^~~~~~~~~~~
/home/marxin/Programming/gcc/gcc/ggc-page.c:980:20: warning: format specifies
type 'void *' but the argument has type 'char *' [-Wformat-pedantic]
entry->page, entry->page + entry->bytes - 1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin
Jakub