Re: #define and (brackets)
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Mon, 24 Nov 2008 17:37:04 -0500
Alan Carre <alan@xxxxxxxxxxxxxxxxx> wrote:
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).
-SHRINK_BOX_AMOUNT won't get parsed as --20, but as - -20 (which will
likely compile just fine, but I'm too lazy to check). Preprocessor works
after lexer, handling tokens rather than individual characters. You need
## operator to create new tokens.
Conversely:
#define SHRINK_BOX_AMOUNT (-20)
CRect rct(l,t,r,b);
rct.DeflateRect(-SHRINK_BOX_AMOUNT, -SHRINK_BOX_AMOUNT);
Compiles fine
Again, there's actually no difference between these two examples.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- Follow-Ups:
- Re: #define and (brackets)
- From: Alan Carre
- Re: #define and (brackets)
- References:
- #define and (brackets)
- From: Gerry Hickman
- Re: #define and (brackets)
- From: David Webber
- Re: #define and (brackets)
- From: Alan Carre
- #define and (brackets)
- Prev by Date: Re: clistctrl question
- Next by Date: Re: Two questions about using shared_ptr
- Previous by thread: Re: #define and (brackets)
- Next by thread: Re: #define and (brackets)
- Index(es):
Relevant Pages
|