Hello! > Hi, > > I was wondering if I could do something like this with a macro in FPC: > > const HASH_TABLE_MASK = $ff; > function GetHashIndex ( hash :dword) :integer; > begin > result := hash AND HASH_TABLE_MASK; > end; > > it's kind of a helper funcion so I don't want to perform the function call > in the > code. > Would the inline modifier make it work without making a function call in > the generated code?
If your goal is performance, i. e. to include the function's body in your code without call and return, simply use the inline feature. I cite the documentation: <cite> 4 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. By default, inline procedures are not allowed. Inline code must be enabled using the command-line switch -Si or {$inline on} directive. Inline code is NOT exported from a unit. This means that when calling an inline procedure from another unit, a normal procedure call will be performed. Only inside units, Inline procedures are really inlined. Recursive inline functions are not allowed. i.e. an inline function that calls itself is not allowed. </cite> E. g. function satured_square(n: integer; max: integer): integer; inline; Every "call" to saturated_square within the same unit will be inlined. HTH Anton Tichawa. ---------- "Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben." Doris Langley Moore: Ada, Countess of Lovelace (London 1977). ---------- Anton Tichawa Volkertstrasse 19 / 20 A-1020 Wien mobil: +43 664 52 07 907 email: [EMAIL PROTECTED] ---------- _______________________________________________ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal