On 6/8/2011 9:20 PM, Julian Leviston wrote:
Tanks everyone for answering on this so much...
Comment/Question below,
On 09/06/2011, at 4:56 AM, Kevin Jones 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?
well, in C++, it is not needed...
for example:
<--
struct Foo
{
...
};
Foo *x;
-->
is valid in C++, but not C.
in C, one could declare the variable as:
"struct Foo *x;"
which also works in C++, but is ugly and redundant.
but, in C, the struct keyword is always needed unless one uses typedef
on it.
<--
typedef struct Foo_s Foo;
struct Foo_s
{
...
};
Foo *x;
-->
the above is valid both in C and C++.
...
struct vtable;
struct object;
struct symbol;
typedef struct object *(*method_t)(struct object *receiver, ...);
...
This is my reasoning... a function pointer "fp" to a function
returning an int and taking an int "h" as an argument is as follows:
int (*fp)(int h);
Now, a function pointer "fp2" to a function returning a pointer to an
integer, taking an integer pointer "x" as an argument would go like
this in my mind:
int *(*fp2)(int *x);
looks about right.
if one added a line:
typedef struct object object_t;
then they could write:
typedef object_t *(*method_t)(object_t *receiver, ...);
Does typedef require that "struct" is included as part of its syntax?
My god, C obfuscates meaning and intention so "well". <sigh> It was
one of my first programming languages, yet I still find it incredibly
difficult. I guess it's just me coming to the sad realisation that I
need to know C (and Math) much better.
apparently, some people don't like using typedef for some reason I am
not entirely sure of...
but, anyways, I personally like vtables and function-pointers in C, as
they are a very powerful and useful feature.
however, my own languages tend to use a less awkward syntax.
_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc