Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-06

overflow checking

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Пётр Косаревский

Just a question about programming practice:

How can I disable overflow checking for a couple of operations?

I use something like that:
{$DEFINE CHECKINGS}
{$IFDEF CHECKINGS} --- of course, this block can be much bigger
  {$R+,S+,Q+,V+}
{$ELSE}
  {$IMPLICITEXCEPTIONS ON}
  {$R-,S-,Q-,V-}
{$ENDIF}

...

a:=b+c;
{$Q-}
e:=f+g;
{$IFDEF CHECKINGS}
  {$R+,S+,Q+,V+}
{$ELSE}
  {$IMPLICITEXCEPTIONS ON}
  {$R-,S-,Q-,V-}
{$ENDIF}
h:=i+j;

etc

So I have many lines overhead each time.
Generally I try to disable checkings for bigger blocks, but it is somewhat lame.

Is there an easier way?
Like
{$SAVE Q} {$Q-} e:=f+g; {$LOAD Q}
so that it will fit one line?

I know, that I can split {$IF} block:
{$Q-} e:=f+g; {$IFDEF CHECK_OVRLW} {Q+} {$ENDIF}

Is this a better practice?

Alexey Pavluchenko
to Пётр Косаревский

Hello Пётр,

Friday, June 23, 2006, 11:59:26 AM, you wrote:

[skip]
ПК> Is there an easier way?
ПК> Like
ПК> {$SAVE Q} {$Q-} e:=f+g; {$LOAD Q}
ПК> so that it will fit one line?

{$IFOPT Q+} {$Q-} {$DEFINE Q_SWITCHED} {$ENDIF}
(* do some stuff here *)
{$IFDEF Q_SWITCHED} {$Q+} {$UNDEF Q_SWITCHED} {$ENDIF}

May not fit in one line though :)

Best regards, Alexey
Vinzent Hoefler
to Пётр Косаревский: Just a question about programming practice: How can I disable overflow checking for a…
Пётр Косаревский wrote
I know, that I can split {$IF} block:

Well, if you do define CHECK_OVERFLW depending on the current compiler's settings like this:

{$IFOPT Q+} {$DEFINE CHECK_OVRLW} {$ENDIF}

then ...

{$Q-} e:=f+g; {$IFDEF CHECK_OVRLW} {Q+} {$ENDIF}

... this looks like one of the easiest ways.

Is this a better practice?

Well, my practice is to use more lines, so that the instruction(s) in question don't get hidden by all the compiler-directives surrounding it.

Like this:

|{$IFOPT Q+} {$DEFINE OPT_Q} {$Q-} {$ENDIF}
|Bit_Working_Reg.L := (Bit_Working_Reg.L * $100) or
|                     Ifd.Lzw^.Input_Buf[Byte_Position_In_Buffer];
|{$IFDEF OPT_Q} {$UNDEF OPT_Q} {$Q+} {$ENDIF}

Your's is certainly shorter, but it depends on a global definition, which is something I'm always trying to avoid.

Vinzent.

Пётр Косаревский
to Vinzent Hoefler

Thank you for advices!

Probably, I'll stick to global definitions.
It seems, that {$IFOPT} doesn't help conserve space when you have to switch checks somewhat often, while greatly helps write code fragments for injection.

(A line starting with {$Q-}, then simple expression, ending with some {$IFDEF ..}...{$ENDIF} sequence seems more readable to me than a company of extra lines or beginning with {$IFOPT}/{$IFDEF}: fewer symbols for eyes to make through.)

From: Vinzent Hoefler

Show quoted text 10 lines
Well, if you do define CHECK_OVERFLW depending on the current compiler's settings like this: {$IFOPT Q+} {$DEFINE CHECK_OVRLW} {$ENDIF} then ... > {$Q-} e:=f+g; {$IFDEF CHECK_OVRLW} {Q+} {$ENDIF} ... this looks like one of the easiest ways. Well, my practice is to use more lines, so that the instruction(s) in question don't get hidden by all the compiler-directives surrounding it.

From: Alexey Pavluchenko

{$IFOPT Q+} {$Q-} {$DEFINE Q_SWITCHED} {$ENDIF} (* do some stuff here *) {$IFDEF Q_SWITCHED} {$Q+} {$UNDEF Q_SWITCHED} {$ENDIF} May not fit in one line though :)