in reply to surprising backwards evaluation order
This strikes me as an odd choice
In a stack machine, it's easier to calculate last what you will need first. The arguments are only needed once the function is called, so it's convenient to calculate the address of the function last.
It's not purely a Perl oddity. Visual Studio .NET 2003's C++ compiler does things in the same order with respect to function pointer vs function argument order:
#include <stdio.h> typedef void (*fp)(int); void f(int) { printf("f()\n"); } fp a() { printf("a()\n"); return &f; } int b() { printf("b()\n"); return 0; } int main() { ((fp)(a()))(b()); // (a())->(b()) return 0; }
outputs
b() a() m()
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: surprising backwards evaluation order
by TimToady (Parson) on Mar 18, 2006 at 02:39 UTC |