"self" keyword

Rick C. Hodgin foxmuldrster@yahoo.com
Thu Jun 14 17:16:00 GMT 2012


David,

Oh!  Well, it doesn't have to be called self. :-)  It could be __self__ 
or whatever would be fine.  I see C99 has __FUNC__ for the current 
function name used in strings.  But, I was thinking more of an actual 
reference to the current function as a function entity, sort of like a 
name substitution.

Best regards,
Rick C. Hodgin

On 06/14/2012 01:08 PM, David Malcolm wrote:
> FWIW "self" today is a perfectly good variable name, and practically all
> C and C++ code that interacts with Python (including the C
> implementation of Python itself) uses "self" to name variables
> throughout: many thousands of projects, many millions of lines of code.
> Having this snatched away as a keyword under some compiler settings
> would be a major PITA.
>
> On Thu, 2012-06-14 at 12:53 -0400, Rick C. Hodgin wrote:
>> Ian,
>>
>> I was thinking C and C++.
>>
>> int myclass::foo(int a)
>> {
>>       // recursion
>>       self(a + 1);
>> }
>>
>> Just out of curiosity, why wouldn't it be accepted back into mainline?
>>
>> Thanks for your help. :-)
>>
>> Best regards,
>> Rick C. Hodgin
>>
>> On 06/14/2012 12:48 PM, Ian Lance Taylor wrote:
>>> "Rick C. Hodgin"<foxmuldrster@yahoo.com>   writes:
>>>
>>>> How hard would it be to implement a "self" keyword extension which
>>>> references the contextual function name wherein it was referenced?
>>>>
>>>> int foo(int a)
>>>> {
>>>>       // recursion
>>>>       self(a + 1);
>>>> }
>>>>
>>>> int food(int a)
>>>> {
>>>>       // recursion
>>>>       self(a + 1);
>>>> }
>>>>
>>>> Obviously not a useful example, but demonstrates that to call each
>>>> function it's in again that it can be done without knowing the
>>>> function name.
>>> I assume you are asking about C?  It would be easy to implement.  The
>>> compiler always know what function it is compiling.  But I don't think
>>> the extension would be accepted back into GCC mainline.
>>>
>>> Ian
>>>
>
>



More information about the Gcc mailing list