Re: #define and (brackets)
- From: "Alan Carre" <alan@xxxxxxxxxxxxxxxxx>
- Date: Tue, 25 Nov 2008 04:30:35 +0700
"David Webber" <dave@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23dF9SKaTJHA.5080@xxxxxxxxxxxxxxxxxxxxxxx
"Gerry Hickman" <gerry666uk2@xxxxxxxxxxxxxxxx> wrote in message
news:%23nDeGJNTJHA.6060@xxxxxxxxxxxxxxxxxxxxxxx
#define DELETE (0x00010000L)
#define READ_CONTROL (0x00020000L)
#define WRITE_DAC (0x00040000L)
#define WRITE_OWNER (0x00080000L)
#define SYNCHRONIZE (0x00100000L)
What's the deal?
The L was once needed to define a 32bit integer, as has been said.
Brackets are quite generally a very good habit to get into in defining
things. They may not make much difference in this case but in many
cases they are absolutely crucial.
Consider either
#define one_more_than(x) x+1
True, but for a numerical constant using brackets may actually *hide* coding
errors. For instance, consider the following:
#define SHRINK_BOX_AMOUNT -20
CRect rct(l,t,r,b);
rct.DeflateRect(-SHRINK_BOX_AMOUNT, -SHRINK_BOX_AMOUNT);
leads to a compiler error (cannot decrement an rvalue). So by leaving out
the brakets you are implicitly saying that this quantity is *negative* which
is something you can't tell without looking at the actual #define.
Conversely:
#define SHRINK_BOX_AMOUNT (-20)
CRect rct(l,t,r,b);
rct.DeflateRect(-SHRINK_BOX_AMOUNT, -SHRINK_BOX_AMOUNT);
Compiles fine, even though that it's clear that the intention is to make a
smaller box, not a larger one.
- Alan Carre
.
- Follow-Ups:
- Re: #define and (brackets)
- From: Igor Tandetnik
- Re: #define and (brackets)
- References:
- #define and (brackets)
- From: Gerry Hickman
- Re: #define and (brackets)
- From: David Webber
- #define and (brackets)
- Prev by Date: Re: Sugestions on learning VC++?
- Next by Date: Re: Sugestions on learning VC++?
- Previous by thread: Re: #define and (brackets)
- Next by thread: Re: #define and (brackets)
- Index(es):
Relevant Pages
|
Loading