public inbox for kernelnewbies@kernelnewbies.org
 help / color / mirror / Atom feed
From: daniel watson <ozzloy@challenge-bot.com>
To: kernelnewbies@kernelnewbies.org
Subject: surround complex macros in ()
Date: Wed, 25 Aug 2021 22:21:44 -0700	[thread overview]
Message-ID: <20210826052144.GA6234@challenge-bot.com> (raw)

let me know if this is the right place to ask.

i recently tried to make a commit adding parentheses around a macro
value.

https://lore.kernel.org/linux-staging/20210817043038.GA9492@challenge-bot.com/

it was rejected as "This is not a real change that is needed."

at first, i thought this meant that the code would be identical with and
without parentheses surrounding a complex macro's definition, when the
macro is just typecasting an expression.  but then i came up with code
where having parens or not changes the meaning of the code.

-------delete-me.c--------
#define with ((int)a)
#define sans (int)a

void main(void){
  int b = 0;
  with++;
  sans++;
}
-------delete-me.c--------

-------terminal--------
$ gcc -o delete-me delete-me.c 
delete-me.c: In function ‘main’:
delete-me.c:7:7: error: lvalue required as increment operand
    7 |   with++;
      |       ^~
-------terminal--------

the compiler complains about the macro defined with parentheses, and
does not have a problem with the other macro defined sans parentheses.
this is only a compile time difference, and maybe that's the only
possible difference that could be made by the parentheses.

i'm curious if there's a way to know for sure that there exists no
possible expression with such a macro in it that would cause a more
subtle difference.  for example, how do i rule out the possibility
that the code could compile and have a different value than expected
at runtime?


as a side note, i signed up for the kernelnewbies mailing list, and i do
not see any messages in my inbox, except a reply to a message i sent
out.  i checked here
in some expression
http://lists.kernelnewbies.org/pipermail/kernelnewbies/

and do not see the message i sent, or the reply to it.

am i seeing the right thing?  did i sign up correctly?  is that the
right page to view the mailing list messages online?


thanks!

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

             reply	other threads:[~2021-08-26  5:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26  5:21 daniel watson [this message]
2021-08-26  7:28 ` surround complex macros in () Greg KH
2021-08-26  9:04 ` Valdis Klētnieks

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210826052144.GA6234@challenge-bot.com \
    --to=ozzloy@challenge-bot.com \
    --cc=kernelnewbies@kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox