Re: #define and (brackets)



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


.



Relevant Pages

  • Re: (long) An AES implementation for 32-bit platforms
    ... locate some coding errors of mine that had splipped ... Change 'void main' to 'int main'. ... compiler of DJGPP with the option -Wall in compilation. ...
    (sci.crypt)
  • PL/C (was: Wonder why IBM code quality is suffering?)
    ... It provided the capability to correct many common coding errors. ... You could actually give PL/C no input. ... PL/C was Cornell University's student PL/1 compiler. ... Search the archives at http://bama.ua.edu/archives/ibm-main.html ...
    (bit.listserv.ibm-main)
  • Re: Custom CRect Question
    ... address of the CRect. ... Since the compiler did not catch it, ... But the existence of the cast operator means you can also write ... GetClientRect is called. ...
    (microsoft.public.vc.mfc)
  • Re: optimierender vorschlag ?
    ... class CLabelObj ... const CRect& GetRect() const ... Compiler zu verwenden, ...
    (microsoft.public.de.vc)