This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RFC: attaching functions to types
- From: Shawn Landden <shawnlandden at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 20 Mar 2015 18:05:39 -0700
- Subject: RFC: attaching functions to types
- Authentication-results: sourceware.org; auth=none
direct-declarator:
( type-qualifier[opt] type-specifier *[opt] identifier[opt] ) .
function-definition
call like so:
type.foo(baz);
typep->foo(baz);
type automatically becomes first parameter, (when used as a function
pointer) and as a pointer to if that was included in definition. if
type is a typedef of void and not a pointer then parameters are passed
the same.
This would be implemented with function name mangling:
__tf_type_identifier(...)
example:
struct foo {
int a
}
int (struct foo *b).add(int f) {
return b->a + f;
}
int main(void) {
struct foo bar;
baz.a = 4;
return baz.add(6);
}
I have been hacking at the source, but it is far from functional.
--
Liberty equality fraternity or death,
Shawn Landden
ChurchOfGit.com