This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: "self" keyword


On Thu, 2012-06-14 at 16:34 -0400, Rick C. Hodgin wrote:
> David,
> 
> Well, I probably don't have a NEED for it.  I've gotten along for 25+ 
> years without it. :-)
> 
> However, what prompted my inquiry is using it would've saved me tracking 
> down a few bugs in recent weeks.  Some prior code was re-used for a 
> similar function, but the name of the recursive calls weren't updated in 
> every case.  It didn't take long to debug, but I realized that had it 
> always been written as self() it never would've been an issue.
> 
> I can also see a use for generated code where there's a base source code 
> template in use with an embedded include file reference that changes as 
> it's generated per pass, such as:
> 
> int step1(int a, int b)
> {
>      #include "\current_task\step1.cpp"
> }
> 
> int step2(int a, int b)
> {
>      #include "\current_task\step2.cpp"
> }
> 
> Using the self() reference for recursion, one could modify stepN.cpp's 
> generator algorithms without having to know or care anything in the 
> wrapper code.  

Wouldn't this do?

#define __self__ step1
int __self__ (int a, int b)
{
  #include "something"
  __self__ (x, y);
}
#undef __self__



Cheers,
Oleg


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]