Page 1 of 1
Procedure Inline keyword
Posted: Tue Aug 02, 2005 8:40 pm
by Dreglor
it has proably been asked before but i didn't find it while searching :\
i think a inline function would be nice.
it would improve speed in some cases and improve readability
there just some times when a procedure call would be nice but the code inside is so small its slower than having inlined.
my raytracer uses alot of this inlining to improve speed becasue of the vector math procedures like DotProducts are tiny but are hardto read and understand in the soup of code when inlined.
so maybe a special procedure keyword such as
Code: Select all
ProcedureInline.f DotProduct(ax.f,ay.f,az.f,bx.f,by.f,bz.f)
ProcedureReturn ax * bx + ay * by + az * bz
EndProcedure
i don't think it would too difficult to implement just replace all procedures with there code
Posted: Tue Aug 02, 2005 8:47 pm
by Dräc
Wait for PB v4 and keyword "Macro"

Posted: Tue Aug 02, 2005 10:44 pm
by Fred
yes, macros will be perfects for such stuffs
Posted: Tue Aug 02, 2005 10:55 pm
by remi_meier
And what about local variables in macros? That's the difference between
inline-procedures and macros!
Fred: Do you plan to implement them like #define or like inline procedures?
Posted: Tue Aug 02, 2005 11:30 pm
by Fred
mostky like #define (with some more flexibility)
Posted: Wed Aug 03, 2005 2:16 am
by Dare2
Good stuff.
In the meantime, Dreglor, why not write the "inline" code in an include file and include whereever needed? That means only one place to make a change rather than hunting through all places where the particular sequence of code is used.
Posted: Sun Jan 13, 2008 12:53 pm
by tinman
Are there any plans to add inline functions (either forced as Dreglor requested or automatic based on something like executable size) or are we stuck with macros?
Posted: Sun Jan 13, 2008 8:58 pm
by Mistrel
What do you need an inline function for that a macro can't provide?
Posted: Sun Jan 13, 2008 10:54 pm
by tinman
Mistrel wrote:What do you need an inline function for that a macro can't provide?
Local variables that do not interfere with the variables already defined everywhere you use the macro.
You can take the address of a procedure (although not sure how that would work if it was forced inline).
A macro can not have a return value (you need to use a fixed known variable name or your macro can only be a single statement).
Posted: Mon Jan 14, 2008 7:58 am
by Mistrel
Ahh, I see. I agree that it would be a nice feature then.
Re: Procedure Inline keyword
Posted: Thu Feb 21, 2013 2:27 pm
by luis
Continuing what tinman
was saying:
- macro's shortcomings (no return values AND side effects) removed
- ability to validate params at compile time
- easier to debug
I was looking to see if a request for inline procedures was already made and found this one.
So, even if we have macros, I would like to have inline procedures as well.
Re: Procedure Inline keyword
Posted: Thu Feb 21, 2013 4:05 pm
by Shield
Inline Procedures should be up to the compiler, imho. That means that the compiler
should decide when to inline a function and when not.
In C/C++ for example, the keyword 'inline' is just a hint to the compiler that this
function might be a case for inlining, but it's entirely up to the compiler.
While I'm usually in favor of such additions I think PB should just decide on its own when it makes sense
to inline a function and when it doesn't. Programmers should just always use a procedure.

Re: Procedure Inline keyword
Posted: Thu Feb 21, 2013 5:44 pm
by netmaestro
Ha, got me. I read this post over twice and was about to reply, 'how is a macro different from what you're describing?' and then I saw all the replies and realized this thread is 8 years old!

Re: Procedure Inline keyword
Posted: Thu Feb 21, 2013 5:53 pm
by luis
... and yet a macro is still different from an inline procedure even if 8 years are passed, some differences are outlined in the posts above
or read here ->
http://en.wikipedia.org/wiki/Inline_function
Re: Procedure Inline keyword
Posted: Mon Nov 18, 2019 3:16 am
by Rinzwind
Why stil no inline procedure?
Very different from macro's... Inline procedures are perfect for short small read/check functions
Short macOS example:
Code: Select all
Procedure kOS(constant.s)
Protected t
t = dlsym_(#RTLD_DEFAULT, constant)
If t
t = PeekI(t)
EndIf
ProcedureReturn t
EndProcedure
How to do this with a macro?