Idea : Expression Type

Don Clugston dac at nospam.com.au
Fri Feb 2 02:57:06 PST 2007


Vladimir Panteleev wrote:
> votes++. However, why not go all the way and implement inline functions? That is, functions which are inlined in the expression using them.
> 
> These would have the following advantages:
> 
>   * using a simple syntax (an "inline" attribute for the function);
>   * since no calls to the function are made, the compiler can decide when to use lazy argument evaluation and when to cache the results;
>   * since it's a function, it's possible to use complex instructions (blocks, loops, etc.)
>   * the code (arguments, return value) simply direct the data flow - there is no real stack frame, the return value is passed immediately and evaluated with the context, etc. Unless there is a strong barrier in the compiler between compiling expressions and statements (so that compound statements could be inlined in expressions), it shouldn't be hard to implement either.
> 
> template div(T)
> {	inline T div(T a, T b)	{ return a/b; }
> }
> void main()
> {	writefln(div!(int)(5,2));
> 	writefln(div!(float)(5.5,2.1));
> }
> 
> What do you think?

???
This has been part of the compiler for a very long time. There's no need 
for the inline keyword, just use the -inline compiler switch and it 
happens automatically.
Or did I miss something?



More information about the Digitalmars-d mailing list