Recent

Author Topic: TFPGList note: how to fix that?  (Read 1176 times)

OldPascal

  • New Member
  • *
  • Posts: 19
TFPGList note: how to fix that?
« on: April 27, 2021, 01:52:28 pm »
I am testing the following code on free pascal compiler,

Code: Pascal  [Select][+][-]
  1. program listtest;
  2.  
  3. uses fgl, SysUtils;
  4. Type
  5.   TIntegerList = specialize TFPGList<Integer>;
  6. Var
  7.   IntList: TIntegerList;
  8.   i: integer;
  9.  
  10. begin
  11.    IntList := TIntegerList.Create;
  12.    IntList.Add(5);
  13.    IntList.Add(10);
  14.    IntList.Add(111);
  15.  
  16.    for  i:=0 to IntList.count-1 do writeln(IntList[i]);
  17.  
  18.   write('Press Enter to close...');
  19.   Readln;
  20. end.
  21.  
  22.  

It compiles but I get a lot of notes (warnings?),

Code: Pascal  [Select][+][-]
  1. Free Pascal Compiler version 3.2.0 [2020/12/18] for x86_64
  2. Copyright (c) 1993-2020 by Florian Klaempfl and others
  3. Target OS: Linux for x86-64
  4. Compiling listtest.pas
  5. fgl.pp(1023,7) Note: Call to subroutine "function TFPGList<System.SmallInt>.Add(const Item:SmallInt):LongInt;" marked as inline is not inlined
  6. fgl.pp(1023,20) Note: Call to subroutine "function TFPGList<System.SmallInt>.Get(Index:LongInt):SmallInt;" marked as inline is not inlined
  7. listtest.pas(12,4) Note: Call to subroutine "function TFPGList<System.SmallInt>.Add(const Item:SmallInt):LongInt;" marked as inline is not inlined
  8. listtest.pas(13,4) Note: Call to subroutine "function TFPGList<System.SmallInt>.Add(const Item:SmallInt):LongInt;" marked as inline is not inlined
  9. listtest.pas(14,4) Note: Call to subroutine "function TFPGList<System.SmallInt>.Add(const Item:SmallInt):LongInt;" marked as inline is not inlined
  10. listtest.pas(16,54) Note: Call to subroutine "function TFPGList<System.SmallInt>.Get(Index:LongInt):SmallInt;" marked as inline is not inlined
  11. Linking listtest
  12. 21 lines compiled, 0.3 sec
  13. 6 note(s) issued
  14. Compilation finished successfully.
  15.  
  16.  

How do I fix the source of notes/warnings?  A clean code does not generates those notes, therefore, I prefer to remove them.
My objective is  for to  pascal generates a choice menu say
1) a
2) b
3) c
4) d

where a...d are strings.
using readln function the user inputs a list of listed numbers which can be one, three or all numbers.  Then I use the user listed numbers to sort the listed strings in the menu according to user's input.  But I have problem with a very simple task - initiating a list.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2023
  • Former Delphi 1-7, 10.2 user
Re: TFPGList note: how to fix that?
« Reply #1 on: April 27, 2021, 02:19:06 pm »
Before 3.2.0 the compiler did not report if it did not inline a function that was marked as inline. Now it does report that and more often than not even with a reason. This way one can see what is really inlined and what is not. (Source: Pascal Dragon)

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
Re: TFPGList note: how to fix that?
« Reply #2 on: April 27, 2021, 02:21:05 pm »
{$notes off} or from the commandline -vn-
It is safe to ignore notes and usually safe to ignore hints (but not warnings)
Code: Pascal  [Select][+][-]
  1. program listtest;
  2. {$notes off}
You can also be more specific and define {$warn 3123 off}
In that case that specific note (not inlined) is turned off.

And at last, when compiling from source, simply do this in fgl.pp: {.$define FGLINLINE}
That disables inlining and hence removes the notes. (Note: note the dot...)

(And these numbers can be obtained by compiling with -vqlhn)

The cleanest solution is 3123, but it is also the less used because most FPC programmers do not even know that option or how to apply it...
That said.. it is fully documented. In an ideal world these numbers would be string consts, though.

I also did a write-up about this in the wiki some years ago:
https://wiki.freepascal.org/Turn_warnings_and_hints_on_or_off
It is somewhat editted later by others...(NOT a smart idea, but so far it stays - about - correct. Not too much damage done, actually it is ruined...)

My write-up above is more correct than the wiki. I will reverse those changes in the wiki.

(Now playing Kill'em All )
https://en.wikipedia.org/wiki/Kill_%27Em_All
« Last Edit: April 27, 2021, 03:30:26 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

OldPascal

  • New Member
  • *
  • Posts: 19
Re: TFPGList note: how to fix that?
« Reply #3 on: April 28, 2021, 01:56:55 am »
Thanks for reply, I tried both methods {$notes off} and {$warn 3123 off} and only first one worked for me.  I still do not understand the inline thing.  I will probably continue my coding with the notes off setting but before I do so I will check out other alternatives of doing the same thing (making a list) without getting that note.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2023
  • Former Delphi 1-7, 10.2 user
Re: TFPGList note: how to fix that?
« Reply #4 on: April 28, 2021, 02:37:37 am »
I still do not understand the inline thing.

From the Free Pascal Reference Guide:

Quote
14.9.5 inline

Procedures that are declared inline are copied to the places where they are called. This has the effect that there is no actual procedure call, the code of the procedure is just copied to where the procedure is needed, this results in faster execution speed if the function or procedure is used a lot. It is obvious that inlining large functions does not make sense.

By default, inline procedures are not allowed. Inline code must be enabled using the command-line switch -Si or {$inline on} directive.

Remark

    * inline is only a hint for the compiler. This does not automatically mean that all calls are inlined; sometimes the compiler may decide that a function simply cannot be inlined, or that a particular call to the function cannot be inlined. If so, the compiler will emit a warning.
    * In old versions of Free Pascal, inline code was not exported from a unit. This meant that when calling an inline procedure from another unit, a normal procedure call will be performed. Only inside units, Inline procedures are really inlined. As of version 2.0.2, inline works across units.
    * Recursive inline functions are not allowed. i. e. an inline function that calls itself is not allowed.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: TFPGList note: how to fix that?
« Reply #5 on: April 28, 2021, 09:03:53 am »
Thanks for reply, I tried both methods {$notes off} and {$warn 3123 off} and only first one worked for me.  I still do not understand the inline thing.  I will probably continue my coding with the notes off setting but before I do so I will check out other alternatives of doing the same thing (making a list) without getting that note.

Note and Hint are the least severe verbosities that FPC provides messages for. In most cases you can simply ignore them (and sometimes you even can't do anything against them). Pay attention to Warning however.

 

TinyPortal © 2005-2018