Recent

Author Topic: FPC and bitwise negation  (Read 5466 times)

Mike James

  • New Member
  • *
  • Posts: 23
FPC and bitwise negation
« on: February 18, 2010, 03:03:54 pm »
I'm interested in language design and I'm writing a compiler for a Oberon-like language using Coco-R. The bitwise negation is define as :

Code: [Select]
Factor =  /* others */ | "NOT" Factor.
This means that the following code fragment is legit:

Code: [Select]
mybool := NOT NOT NOT NOT mybool;
I checked the same code fragment under FreePascal and this allows it also.

It got me thinking: Should it be flagged as a warning (or even a mild rebuke  :D) and when would it ever be useful to allow such a construction?

-=mike=-

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12535
  • FPC developer.
Re: FPC and bitwise negation
« Reply #1 on: February 21, 2010, 03:15:17 am »
Repeated unary NOTs are fairly easily optimizable, and logically sound (though redundant) so why would one unnecesarily burden the compiler (and increase warning/hint noise)?

Both the compiler developer and user have better things to do.

Only exception I can imagine is compilers and, more importantly, source analysers for training/educational purposes. 

 

TinyPortal © 2005-2018