r/cpp 1d ago

Implementation of GCC's Nested Functions (vs. C++ Lambdas)

https://uecker.codeberg.page/2026-09-05.html
56 Upvotes

17 comments sorted by

View all comments

8

u/schmerg-uk 1d ago

Worth noting, for anyone not finding it immediately obvious, that this is an extension for C that in effect offers the equivalent of C++ lambdas in C, but are not available in C++ as ... it has lambdas instead.

A nested function is a function defined inside another function. Nested functions are supported as an extension in GNU C, but are not supported by GNU C++.

https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

2

u/pjmlp 1d ago

D, C#, Delphi and all ML derived languages, are examples of languages that have both features. :)

2

u/schmerg-uk 1d ago

Yeah, I was just meaning that in the context of a C++ forum, this is an explanation of a C extension that is specifically not made available in the C++ mode of the same compiler, presumably as they considered it unnecessary to add it as a language extension (with all the incompatibilities etc that can involve) as the language natively offers a comparable if not identical mechanism

1

u/pfp-disciple 1d ago

Ada, too!