On 6/8/2011 11:36 PM, Julian Leviston wrote:
Answering my own question...
On 09/06/2011, at 4:27 PM, Julian Leviston wrote:
See below...
On 09/06/2011, at 2:59 PM, Josh Gargus wrote:
I really don't understand what this means:
typedef struct object *(*method_t)(struct object *receiver, ...);
method_t is a pointer to a function that returns an object pointer
and takes receiver and additional argument
Thanks for this. Okay, I understand that, but why is there a
"struct" in there twice? considering object is defined as a struct
earlier in the piece... is it because they're object pointers? when
specifying a struct pointer, do you need to write "struct" even
though you've previously specified a struct with that name?
The latter. In C++ you only need to use struct when declaring the
type. However, in C you need to explicitly use struct every time
you want to refer to the type.
One common idiom is to use a typedef while defining the type. In
this case, you might write:
typedef struct object object_t;
typedef object_t *(*method_t)(object_t *receiver, ...);
Okay, so in the initial example, why the typedef? What function is it
performing here? I thought typedef was used to alias types, and yet
here it doesn't seem to be doing anything... if method_t is a
function pointer, why does there need to be a typedef in front of it?
Sorry I'm so dense. :S
Julian.
So basically adding typedef defines the function pointer as a type,
whereas leaving it off simply creates a variable function pointer. I
*think* I've finally wrapped my head around this now. Gosh.
Julian.
yep...
function pointers are fun, and isn't the syntax just so aesthetically
pleasing?...
now, just what could make it any better?...
... half imagined something here (involving some C++0x features) which
was too terrible to be described (or typed...).
for now, one can just settle with this:
typedef void *(*(*foo)(int x))(void *(*(*bar)(int y))(int z));
but, in all this, it has managed to cause me a little bit of doubt as to
the "intuitiveness" of (in my language) using a number of modifier
keywords to alter the behavior of variable scoping semantics...
var x; //does one thing (default/lexical scope)
dynamic var x; //dynamic scope (except on a class)
delegate var x; //delegation scope
nevermind:
typedef function Foo(x, y);
Foo x;
note, the language currently has several valid declaration styles as
well, the above being one of them.
and, recently, a disagreement with someone (Thomas Mertes) over
basically hard-coding nearly everything language-wise at present into
the VM... (but, for my uses, extending the language from within the
language isn't really a pressing issue...).
and, in the past, with someone else over the issue that my type-system
is based in large-part on type-name strings and "magic pointers" (as
opposed to tagged references or similar and type-numbers or similar).
but... name-strings were easier to work with (and don't require a
centralized table of assigned type numbers, or similar).
well, and that at present, I have opcodes numbered up to around 556
(this being in the 2-byte range, with opcodes 0..191 as single byte, and
256 to 16383 as 2-byte, with 192..255 currently as an unusable "hole"
due to an implementation detail, roughly along the lines of handling
2-byte opcodes via switch-recursion).
but, sadly, some of my stuff gets "hairy" sometimes.
or such...
_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc