[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: uninitialized struct members
From: |
Jim Meyering |
Subject: |
Re: uninitialized struct members |
Date: |
Sun, 22 Nov 2009 09:11:09 +0100 |
Bruno Haible wrote:
>
>> > - struct partition part;
>> > + struct partition part IF_LINT (= { .xmid = 0, .ymid = 0 });
>>
>> Any code using a one-argument macro like that is rejected,
>> due to the comma:
>>
>> ../lib/diffseq.h:467:64: error: macro "IF_LINT" passed 2 arguments,\
>> but takes just 1
>>
>> FYI, I tried the same thing before writing the #if-adding patch.
>
> OK, if we both fall into the same trap, it's certainly worth adding a comment.
>
> How about the appended patch? Can I commit this in your name? Or in my name?
> (By default, when combining ideas from several people in a patch, I choose as
> --author the person who has contributed the majority of ideas or code.)
I have no objection to the practice, in general.
The only trouble is when a modification induces incorrectness
or a stylistic disagreement.
>> Please do not push that, at least not with my name on it...
>
> Oops, glad that I forgot to push it...
...
> -/* Use this to suppress gcc's `...may be used before initialized' warnings.
> */
> +/* Use this to suppress gcc's `...may be used before initialized' warnings.
> + Beware: The Code argument must not contain commas. */
> #ifndef IF_LINT
> # ifdef lint
> # define IF_LINT(Code) Code
> @@ -465,6 +466,8 @@
> else
> {
> struct partition part;
> + IF_LINT (part.xmid = 0;)
> + IF_LINT (part.ymid = 0;)
I avoid using IF_LINT (stmt;) because the result can no longer
be handled properly by automatic code formatters;
I would prefer this:
>From 672ecc5c795cd74d36a3e4fad3afe5070b3196d0 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sun, 22 Nov 2009 09:01:07 +0100
Subject: [PATCH] diffseq: avoid spurious gcc warnings
* lib/diffseq.h (IF_LINT2): Define.
(compareseq): Use it to initialize two members of "part".
This avoids two used-uninitialized warnings.
---
ChangeLog | 7 +++++++
lib/diffseq.h | 11 ++++++++++-
2 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 04b2a6b..9f8d4ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-11-22 Jim Meyering <address@hidden>
+
+ diffseq: avoid spurious gcc warnings
+ * lib/diffseq.h (IF_LINT2): Define.
+ (compareseq): Use it to initialize two members of "part".
+ This avoids two used-uninitialized warnings.
+
2009-11-21 Jim Meyering <address@hidden>
c-stack: avoid "ignoring return value of `write'" warning
diff --git a/lib/diffseq.h b/lib/diffseq.h
index 0c1723f..9c7baa6 100644
--- a/lib/diffseq.h
+++ b/lib/diffseq.h
@@ -77,6 +77,15 @@
# endif
#endif
+/* As above, but when Code must contain one comma. */
+#ifndef IF_LINT2
+# ifdef lint
+# define IF_LINT2(Code1, Code2) Code1, Code2
+# else
+# define IF_LINT2(Code1, Code2) /* empty */
+# endif
+#endif
+
/*
* Context of comparison operation.
*/
@@ -464,7 +473,7 @@ compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET
ylim,
}
else
{
- struct partition part;
+ struct partition part IF_LINT2 (= { .xmid = 0, .ymid = 0 });
/* Find a point of correspondence in the middle of the vectors. */
diag (xoff, xlim, yoff, ylim, find_minimal, &part, ctxt);
--
1.6.5.2