Re: [PATCH] staging: iio: meter: enclose Macros with complex values in parentheses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On ١٢‏/٣‏/٢٠٢٣ ١٦:١٢, Julia Lawall wrote:

On Sun, 12 Mar 2023, Menna Mahmoud wrote:

enclose Macros with complex values in parentheses is especially useful
in making macro definitions “safe” (so that they
evaluate each operand exactly once).
enclose -> Enclose, and Macros -> macros

I don't understand the above comment though.  How does adding parentheses
around the body of a macro cause the operands to be evaluated only once?
And the macros that you have changed don't have any operands.

The value of adding parentheses is normally to ensure that the body of the
macro doesn't interact with the context in a weird way.  For example, you
could have

#define ADD 3 + 4

Then if you use your macro as 6 * ADD, you will end up evaluating
6 * 3 + 4, ie 18 + 4, when you might have expected 6 * 7.  The issue is
that * has higher precedence than +.

yes, I mean that but i couldn't explain it well, thanks for your feedback.

But I don't think that such a problem can arise with a cast expression, so
parentheses around it should not be necessary.

So, no need for this patch?

this error reported by
this error is reported by checkpatch.

"ERROR: Macros with complex values should be enclosed in parentheses"

macros and this error fixed by enclose these macros in parentheses.
The last two lines aren't needed.  One can easily see that from looking at
the patch.

Got it, Thank you.



Signed-off-by: Menna Mahmoud <>
  drivers/staging/iio/meter/ade7854.h | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/meter/ade7854.h b/drivers/staging/iio/meter/ade7854.h
index 7a49f8f1016f..41eeedef569b 100644
--- a/drivers/staging/iio/meter/ade7854.h
+++ b/drivers/staging/iio/meter/ade7854.h
@@ -139,9 +139,9 @@
  #define ADE7854_MAX_RX    7
  #define ADE7854_STARTUP_DELAY 1000

-#define ADE7854_SPI_SLOW	(u32)(300 * 1000)
-#define ADE7854_SPI_BURST	(u32)(1000 * 1000)
-#define ADE7854_SPI_FAST	(u32)(2000 * 1000)
+#define ADE7854_SPI_SLOW	((u32)(300 * 1000))
+#define ADE7854_SPI_BURST	((u32)(1000 * 1000))
+#define ADE7854_SPI_FAST	((u32)(2000 * 1000))

   * struct ade7854_state - device instance specific data


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     []

  Powered by Linux