This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: attaching functions to types
- From: Shawn Landden <shawnlandden at gmail dot com>
- To: Andrew Pinski <pinskia at gmail dot com>
- Cc: GCC Mailing List <gcc at gcc dot gnu dot org>
- Date: Mon, 23 Mar 2015 12:02:23 -0700
- Subject: Re: RFC: attaching functions to types
- Authentication-results: sourceware.org; auth=none
- References: <CAJusiZX-_OMfy+cD6LSQOUOK7R4u-_8LQEaFVia2DAb9NOw9mA at mail dot gmail dot com> <CA+=Sn1nEegnMOiNE9qZRGEt-i=Chq8hu6pWNU_Y6i47m=vVd+A at mail dot gmail dot com> <CAJusiZV9fRCA-sdwEd=qqVV6aQqNzSTqXwte15QBkgeyEidLrA at mail dot gmail dot com> <CA+=Sn1n9Ui1KOsCy8hEOAqhsvC-6QWWPPEARfWUz-oQK-nwooQ at mail dot gmail dot com>
On Mon, Mar 23, 2015 at 11:39 AM, Andrew Pinski <pinskia@gmail.com> wrote:
> On Mon, Mar 23, 2015 at 11:32 AM, Shawn Landden <shawnlandden@gmail.com> wrote:
>> On Fri, Mar 20, 2015 at 6:36 PM, Andrew Pinski <pinskia@gmail.com> wrote:
>>> On Fri, Mar 20, 2015 at 6:05 PM, Shawn Landden <shawnlandden@gmail.com> wrote:
>>>> direct-declarator:
>>>> ( type-qualifier[opt] type-specifier *[opt] identifier[opt] ) .
>>>> function-definition
>>>>
>>>>
>>>> call like so:
>>>>
>>>>
>>>> type.foo(baz);
>>>> typep->foo(baz);
>>>
>>>
>>> Wait you are re-inventing C with classes and C++.
>> This is still C, unlike C++. I was influenced by Go.
>
>
> Have you read about C with classes and the history around C++? C with
> classes was still a super-set of C in the first couple of years, only
> later becoming C++ when it started to become a language in its own
> rights. Again what is the difference between your ideas and C with
> classes?
I like Go using upper case to determine public/private, but otherwise
yes, its basically the same.
Interesting that I came to the same conclusion. Also, I would disagree
with a mandatory constructor function. The advantage of the C with
classes method is that there is only one place to look for function
pointers, rather than having it a fallback namespace, the disadvantage
is that it makes it seem that offsetof() will work.
>
> Thanks,
> Andrew
>
>>>
>>> Thanks,
>>> Andrew
>>>
>>>>
>>>> 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
>>
>>
>>
>> --
>> Liberty equality fraternity or death,
>>
>> Shawn Landden
>> ChurchOfGit.com
--
Liberty equality fraternity or death,
Shawn Landden
ChurchOfGit.com