Recent

Author Topic: how to finely control compiler hint generation ?  (Read 4051 times)

440bx

  • Hero Member
  • *****
  • Posts: 3945
how to finely control compiler hint generation ?
« on: December 25, 2018, 06:54:42 am »
Hello,

I'm trying to tell the compiler to suppress hints for a specific piece of code without success.  For instance, in the example below:
Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC                      }
  2.  
  3. {$LONGSTRINGS    OFF               }
  4. {$WRITEABLECONST ON                }
  5. {$TYPEDADDRESS   ON                }
  6.  
  7. program HintTest;
  8.  
  9. const
  10.   {$PUSH} {$HINTS OFF}
  11.   const_1  = 1;
  12.   const_2  = 2;
  13.   const_3  = 3;
  14.   {$POP} //{$HINTS ON}
  15.  
  16. begin
  17.   writeln(const_1);
  18. end.
  19.  
I'd like the compiler _not_ to generate any hints about const_2 and const_3 not being used.  I tried turning hints off and on, tried about the same thing using push and pop but all to no avail.

the question is: how do I suppress hints for that specific section of the code ?

Thank you for your help.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: how to finely control compiler hint generation ?
« Reply #1 on: December 25, 2018, 10:23:42 am »
« Last Edit: December 25, 2018, 10:25:39 am by Thaddy »
Specialize a type, not a var.

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: how to finely control compiler hint generation ?
« Reply #2 on: December 25, 2018, 11:34:12 am »
the question is: how do I suppress hints for that specific section of the code ?
The answer is in the question: the code section, not the section before it.
Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}
  2.  
  3. procedure Test;
  4. const
  5.   NotUsedConst = 1;
  6. {$HINTS OFF}
  7. begin
  8. end;
  9. {$HINTS ON}
  10.  
  11. begin
  12.   Test;
  13. end.

440bx

  • Hero Member
  • *****
  • Posts: 3945
Re: how to finely control compiler hint generation ?
« Reply #3 on: December 25, 2018, 12:51:26 pm »
The answer is in the question: the code section, not the section before it.
Excellent, thank you.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

440bx

  • Hero Member
  • *****
  • Posts: 3945
Re: how to finely control compiler hint generation ?
« Reply #4 on: December 25, 2018, 01:08:25 pm »
Now I have another question directly related to the original one.

I have not been able to find the options (in Lazarus) that would show the warnings/hints numbers.  I need those to choose which ones to turn off individually but, none of switches I've tried so far yields the hint/warning numbers.   All I always  seem to get is the line number/column and text message, no hint/warning number.

The question is: how do I get to see the hint/warning number when compiling from Lazarus ?

Thank you.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: how to finely control compiler hint generation ?
« Reply #5 on: December 25, 2018, 01:27:02 pm »
The question is: how do I get to see the hint/warning number when compiling from Lazarus ?
Are you asking about that:

440bx

  • Hero Member
  • *****
  • Posts: 3945
Re: how to finely control compiler hint generation ?
« Reply #6 on: December 25, 2018, 01:31:57 pm »
Are you asking about that:
Yes!... thank you Serge. 

I gotta do more right clicking around in Lazarus. :)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: how to finely control compiler hint generation ?
« Reply #7 on: December 25, 2018, 02:02:51 pm »
the question is: how do I suppress hints for that specific section of the code ?
The answer is in the question: the code section, not the section before it.
Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}
  2.  
  3. procedure Test;
  4. const
  5.   NotUsedConst = 1;
  6. {$HINTS OFF}
  7. begin
  8. end;
  9. {$HINTS ON}
  10.  
  11. begin
  12.   Test;
  13. end.
That is wrong and you know that. If hints were already off you put them - unconditionally - on. You should respect current state. Use push and pop.
Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}
  2.  
  3. procedure Test;
  4. const
  5.   NotUsedConst = 1;
  6. {$PUSH}{$HINTS OFF}
  7. begin
  8. end;
  9. {$HINTS ON}{$POP}
  10.  
  11. begin
  12.   Test;
  13. end.

This is especially important to teach people who do not know how to handle conditionals, as is the case here.
« Last Edit: December 25, 2018, 02:06:02 pm by Thaddy »
Specialize a type, not a var.

440bx

  • Hero Member
  • *****
  • Posts: 3945
Re: how to finely control compiler hint generation ?
« Reply #8 on: December 25, 2018, 02:31:14 pm »
This is especially important to teach people who do not know how to handle conditionals, as is the case here.
LOL... you never change.  That's great.

Since you're sporting your pontificating talent, here the better way of doing it ...
Code: Pascal  [Select][+][-]
  1. {$PUSH} {$WARN 5028 OFF}
That way, you don't turn all the hints/warnings off... "somewhat" important... of course, you knew that.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: how to finely control compiler hint generation ?
« Reply #9 on: December 25, 2018, 02:57:49 pm »
You forgot the {$pop}  ;D And you'd better  read the wiki, because that is correct.
Specialize a type, not a var.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: how to finely control compiler hint generation ?
« Reply #10 on: December 25, 2018, 05:55:48 pm »
That is wrong and you know that. If hints were already off you put them - unconditionally - on. You should respect current state. Use push and pop.
Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}
  2.  
  3. procedure Test;
  4. const
  5.   NotUsedConst = 1;
  6. {$PUSH}{$HINTS OFF}
  7. begin
  8. end;
  9. {$HINTS ON}{$POP}
  10.  
  11. begin
  12.   Test;
  13. end.

This is especially important to teach people who do not know how to handle conditionals, as is the case here.

The {$HINTS ON} is superfluous here as {$POP} already takes care of that.  ;)

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: how to finely control compiler hint generation ?
« Reply #11 on: December 25, 2018, 06:16:01 pm »
 :) Yes. Btw: happy birthday, albeit belated...
Specialize a type, not a var.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: how to finely control compiler hint generation ?
« Reply #12 on: December 25, 2018, 07:08:42 pm »
Thanks, even though it's a very belated one  :P

 

TinyPortal © 2005-2018