[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] avoid misc. warnings
From: |
Jim Meyering |
Subject: |
Re: [PATCH] avoid misc. warnings |
Date: |
Thu, 05 Feb 2009 11:07:33 +0100 |
Bruno Haible <address@hidden> wrote:
> Jim Meyering wrote:
>> I wrote these changes some time ago, and
>> am going to push them shortly.
>>
>> +#undef UNUSED_PARAM
>> +#ifdef __linux__
>> +# define UNUSED_PARAM _UNUSED_PARAMETER_
>> +#else
>> +# define UNUSED_PARAM
>> +#endif
>> +
>> ...
>>
>> +#undef UNUSED_PARAM
>> +#ifdef GETFSTYP
>> +# define UNUSED_PARAM
>> +#else
>> +# define UNUSED_PARAM _UNUSED_PARAMETER_
>> +#endif
>> +
>
> Now this gets really ugly. Not only because a macro with the same name is
> being
> undefined and redefined repeatedly, but also because the #if conditions for
> this macro must be the same as the #if conditions inside the function's body.
> When they get out of sync, the warning will reappear.
>
> The other way to silence this warning is a statement
> (void)param;
> in the function's body. (Or was there some problem with that? I just tested
> gcc 2.95.3 to 4.3.2, and in all versions such a void cast makes the warning
> disappear.)
>
> Bottom line: Whenever the _UNUSED_PARAMETER_ macro cannot be used
> unconditionally, I would use a cast to void.
Thanks for the prod.
While cast-to-void is not enough to avoid ignored-return-value
warnings, it is enough to avoid "unused-parameter" warnings,
so I'm adjusting like this:
>From 17b968b1e82e9cf033d7f1035031baadd8e161a0 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 5 Feb 2009 11:02:05 +0100
Subject: [PATCH] still avoid unused-parameter warnings, but do it cleanly
* lib/fsusage.c (UNUSED_PARAM): Remove definition.
(get_fs_usage): Cast to void instead.
* lib/mountlist.c (UNUSED_PARAM): Remove definition.
(dev_from_mount_options, read_file_system_list): Cast to void.
Prompted by Bruno Haible.
---
lib/fsusage.c | 10 ++--------
lib/mountlist.c | 23 +++++------------------
2 files changed, 7 insertions(+), 26 deletions(-)
diff --git a/lib/fsusage.c b/lib/fsusage.c
index e11fd14..ade4195 100644
--- a/lib/fsusage.c
+++ b/lib/fsusage.c
@@ -84,12 +84,6 @@
otherwise, use PROPAGATE_ALL_ONES. */
#define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1))
-#ifdef STAT_READ_FILSYS
-# define UNUSED_PARAM /* empty */
-#else
-# define UNUSED_PARAM _UNUSED_PARAMETER_
-#endif
-
/* Fill in the fields of FSP with information about space usage for
the file system on which FILE resides.
DISK is the device on which FILE is mounted, for space-getting
@@ -98,9 +92,9 @@
ERRNO is either a system error value, or zero if DISK is NULL
on a system that requires a non-NULL value. */
int
-get_fs_usage (char const *file, char const *disk UNUSED_PARAM,
- struct fs_usage *fsp)
+get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
{
+ (void) disk; /* avoid argument-unused warning */
#if defined STAT_STATVFS /* POSIX */
struct statvfs fsd;
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 119cdf0..6010e27 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -1,6 +1,6 @@
/* mountlist.c -- return a list of mounted file systems
- Copyright (C) 1991, 1992, 1997-2008 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1997-2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -297,17 +297,10 @@ fstype_to_string (int t)
#if defined MOUNTED_GETMNTENT1 || defined MOUNTED_GETMNTENT2
-#undef UNUSED_PARAM
-#ifdef __linux__
-# define UNUSED_PARAM _UNUSED_PARAMETER_
-#else
-# define UNUSED_PARAM
-#endif
-
/* Return the device number from MOUNT_OPTIONS, if possible.
Otherwise return (dev_t) -1. */
static dev_t
-dev_from_mount_options (char const *mount_options UNUSED_PARAM)
+dev_from_mount_options (char const *mount_options)
{
/* GNU/Linux allows file system implementations to define their own
meaning for "dev=" mount options, so don't trust the meaning
@@ -332,30 +325,24 @@ dev_from_mount_options (char const *mount_options
UNUSED_PARAM)
}
# endif
-
+ (void) mount_options;
return -1;
}
#endif
-#undef UNUSED_PARAM
-#ifdef GETFSTYP
-# define UNUSED_PARAM
-#else
-# define UNUSED_PARAM _UNUSED_PARAMETER_
-#endif
-
/* Return a list of the currently mounted file systems, or NULL on error.
Add each entry to the tail of the list so that they stay in order.
If NEED_FS_TYPE is true, ensure that the file system type fields in
the returned list are valid. Otherwise, they might not be. */
struct mount_entry *
-read_file_system_list (bool need_fs_type UNUSED_PARAM)
+read_file_system_list (bool need_fs_type)
{
struct mount_entry *mount_list;
struct mount_entry *me;
struct mount_entry **mtail = &mount_list;
+ (void) need_fs_type;
#ifdef MOUNTED_LISTMNTENT
{
--
1.6.1.2.511.gc5d3f