Re: Help needed with walk_dir()
- Posted by mattlewis (admin) Aug 04, 2010
- 1027 views
You say that routine_id() is "sort of" a pointer to a function, is this how it is actually implemented in the C source code for Euphoria?
It's a pointer in that it "points to" your routine. It does not refer to a particular place in memory (which is what is commonly meant when someone talks about a pointer). Effectively, you could think of it where the back end maintains a list of the routines, and the routine id is the index into that list. It's basically equivalent to:
procedure foo() -- ...do stuff end procedure procedure bar() -- ...do stuff end procedure procedure baz() -- ...do stuff end procedure sequence ROUTINES = {"foo", "bar", "baz"} function my_routine_id( sequence name ) return find( name, ROUTINES ) end function procedure my_call_proc( integer id ) if id = 1 then foo() elsif id = 2 then bar() elseif id = 3 then baz() else -- crash, bad routine id! end if end procedure integer foo_id foo_id = my_routine_id("foo") my_call_proc( foo_id )
I have to confess this is making my head hurt, but I'd really like to understand it. I'm not going to attempt reading the source code, but I have a book on C which has been gathering dust on my shelf for years, time to take a look at it I think. I know that "The C Programming Language" is highly recommended, but maybe tough going for newbies like me...
You can also get a better feel by looking at the euphoria based back end. It's still pretty dense, and not terribly easy to jump right into, but there is an implementation of routine id built in pure euphoria in there.
Matt