Thread overview
C has nested classes, really?
Dec 29, 2005
James Dunne
Dec 29, 2005
Matthew
Dec 29, 2005
Walter Bright
Dec 29, 2005
Matthew
Dec 29, 2005
John C
Dec 29, 2005
Walter Bright
December 29, 2005
http://www.digitalmars.com/d/comparison.html

Wow, must've missed something about C a while back! =P
December 29, 2005
And C++ does have perfectly adequate, albeit indirect, support for nested functions: http://www.cuj.com/documents/s=9949/cuj1135208707797/flex_14.htm

;-)

"James Dunne" <james.jdunne@gmail.com> wrote in message news:dp1fmc$ole$1@digitaldaemon.com...
> http://www.digitalmars.com/d/comparison.html
>
> Wow, must've missed something about C a while back! =P


December 29, 2005
> "James Dunne" <james.jdunne@gmail.com> wrote
>> Wow, must've missed something about C a while back! =P

"Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:dp1hha$pvh$1@digitaldaemon.com...
> And C++ does have perfectly adequate, albeit indirect, support for nested functions: http://www.cuj.com/documents/s=9949/cuj1135208707797/flex_14.htm

I'd disagree with "perfectly adequate." C++ nested functions cannot access local variables in their enclosing functions, necessitating a bunch of extra code to transfer any needed data.

In your article, this advantage of D nested functions is not used because you're using a C callback function. If the callback function was a D delegate, the code becomes dramatically simpler:

HWND FindFirstChildById(HWND hwndParent, int id)
{
  if(GetDlgCtrlID(hwndParent) == id)
  {
    return hwndParent;
  }
  else
  {
      HWND  hwndChild;

    BOOL FindChildProc(HWND hwnd)
    {
      return (GetDlgCtrlID(hwnd) == id)
              ? (hwndChild = hwnd, false)
              : true;
    }

    EnumChildWindows(hwndParent, &FindChildProc);

    return hwndChild;
  }
}



December 29, 2005
"Walter Bright" <newshound@digitalmars.com> wrote in message news:dp1jf1$rjn$1@digitaldaemon.com...
> > "James Dunne" <james.jdunne@gmail.com> wrote
> >> Wow, must've missed something about C a while back! =P
>
> "Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:dp1hha$pvh$1@digitaldaemon.com...
> > And C++ does have perfectly adequate, albeit indirect, support for
nested
> > functions: http://www.cuj.com/documents/s=9949/cuj1135208707797/flex_14.htm
>
> I'd disagree with "perfectly adequate." C++ nested functions cannot access local variables in their enclosing functions, necessitating a bunch of
extra
> code to transfer any needed data.
>
> In your article, this advantage of D nested functions is not used because you're using a C callback function. If the callback function was a D delegate, the code becomes dramatically simpler:
>
> HWND FindFirstChildById(HWND hwndParent, int id)
> {
>   if(GetDlgCtrlID(hwndParent) == id)
>   {
>     return hwndParent;
>   }
>   else
>   {
>       HWND  hwndChild;
>
>     BOOL FindChildProc(HWND hwnd)
>     {
>       return (GetDlgCtrlID(hwnd) == id)
>               ? (hwndChild = hwnd, false)
>               : true;
>     }
>
>     EnumChildWindows(hwndParent, &FindChildProc);
>
>     return hwndChild;
>   }
> }
>

True. I forgot about that aspect. :$


December 29, 2005
"Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:dp1n8l$unj$1@digitaldaemon.com...
>
> "Walter Bright" <newshound@digitalmars.com> wrote in message news:dp1jf1$rjn$1@digitaldaemon.com...
>> > "James Dunne" <james.jdunne@gmail.com> wrote
>> >> Wow, must've missed something about C a while back! =P
>>
>> "Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:dp1hha$pvh$1@digitaldaemon.com...
>> > And C++ does have perfectly adequate, albeit indirect, support for
> nested
>> > functions: http://www.cuj.com/documents/s=9949/cuj1135208707797/flex_14.htm
>>
>> I'd disagree with "perfectly adequate." C++ nested functions cannot
>> access
>> local variables in their enclosing functions, necessitating a bunch of
> extra
>> code to transfer any needed data.
>>
>> In your article, this advantage of D nested functions is not used because you're using a C callback function. If the callback function was a D delegate, the code becomes dramatically simpler:
>>
>> HWND FindFirstChildById(HWND hwndParent, int id)
>> {
>>   if(GetDlgCtrlID(hwndParent) == id)
>>   {
>>     return hwndParent;
>>   }
>>   else
>>   {
>>       HWND  hwndChild;
>>
>>     BOOL FindChildProc(HWND hwnd)
>>     {
>>       return (GetDlgCtrlID(hwnd) == id)
>>               ? (hwndChild = hwnd, false)
>>               : true;
>>     }
>>
>>     EnumChildWindows(hwndParent, &FindChildProc);
>>
>>     return hwndChild;
>>   }
>> }
>>
>
> True. I forgot about that aspect. :$
>

Er, not quite. EnumChildWindows expects a pointer to a static function, not a delegate.


December 29, 2005
"John C" <johnch_atms@hotmail.com> wrote in message news:dp1npr$v7k$1@digitaldaemon.com...
> Er, not quite. EnumChildWindows expects a pointer to a static function, not a delegate.

Right, which is why the D version in the article is forced to do it that way. If you're calling a D function, you'd use a delegate.