<s>
Blocks	O
are	O
a	O
non-standard	O
extension	O
added	O
by	O
Apple	O
Inc	O
.	O
to	O
Clang	B-Application
's	O
implementations	O
of	O
the	O
C	B-Language
,	O
C++	B-Language
,	O
and	O
Objective-C	B-Language
programming	I-Language
languages	I-Language
that	O
uses	O
a	O
lambda	O
expression-like	O
syntax	O
to	O
create	O
closures	B-Language
within	O
these	O
languages	O
.	O
</s>
<s>
Apple	O
designed	O
blocks	O
with	O
the	O
explicit	O
goal	O
of	O
making	O
it	O
easier	O
to	O
write	O
programs	O
for	O
the	O
Grand	B-Operating_System
Central	I-Operating_System
Dispatch	I-Operating_System
threading	O
architecture	O
,	O
although	O
it	O
is	O
independent	O
of	O
that	O
architecture	O
and	O
can	O
be	O
used	O
in	O
much	O
the	O
same	O
way	O
as	O
closures	B-Language
in	O
other	O
languages	O
.	O
</s>
<s>
Apple	O
has	O
implemented	O
blocks	O
both	O
in	O
their	O
own	O
branch	O
of	O
the	O
GNU	B-Application
Compiler	I-Application
Collection	I-Application
and	O
in	O
the	O
upstream	O
Clang	B-Application
LLVM	B-Application
compiler	O
front	O
end	O
.	O
</s>
<s>
Language	O
runtime	B-Library
library	I-Library
support	O
for	O
blocks	O
is	O
also	O
available	O
as	O
part	O
of	O
the	O
LLVM	B-Application
project	O
.	O
</s>
<s>
The	O
Khronos	O
group	O
uses	O
blocks	O
syntax	O
to	O
enqueue	O
kernels	O
from	O
within	O
kernels	O
as	O
of	O
version	O
2.0	O
of	O
OpenCL	B-Application
.	O
</s>
<s>
Unlike	O
ordinary	O
C	B-Language
function	O
definitions	O
,	O
their	O
value	O
can	O
capture	O
state	O
from	O
their	O
surrounding	O
context	O
.	O
</s>
<s>
The	O
blocks	O
runtime	O
is	O
not	O
part	O
of	O
the	O
C	B-Language
library(s )	O
linked	O
by	O
default	O
on	O
some	O
systems	O
.	O
</s>
<s>
The	O
runtime	O
is	O
a	O
part	O
of	O
clang	B-Application
's	O
runtime	O
,	O
but	O
is	O
sometimes	O
not	O
installed	O
with	O
the	O
clang	B-Application
package	O
.	O
</s>
<s>
Blocks	O
bear	O
a	O
superficial	O
resemblance	O
to	O
GCC	B-Application
's	O
extension	O
of	O
C	B-Language
to	O
support	O
lexically	O
scoped	O
nested	O
functions	O
.	O
</s>
<s>
However	O
,	O
GCC	B-Application
's	O
nested	O
functions	O
,	O
unlike	O
blocks	O
,	O
must	O
not	O
be	O
called	O
after	O
the	O
containing	O
scope	O
has	O
exited	O
,	O
as	O
that	O
would	O
result	O
in	O
undefined	B-Language
behavior	I-Language
.	O
</s>
<s>
GCC-style	O
nested	O
functions	O
currently	O
use	O
dynamic	O
creation	O
of	O
executable	O
thunks	B-Application
on	O
most	O
architectures	O
when	O
taking	O
the	O
address	O
of	O
the	O
nested	O
function	O
.	O
</s>
<s>
On	O
most	O
architectures	O
(	O
including	O
X86	O
)	O
,	O
these	O
thunks	B-Application
are	O
created	O
on	O
the	O
stack	O
,	O
which	O
requires	O
marking	O
the	O
stack	O
executable	O
.	O
</s>
<s>
Blocks	O
do	O
not	O
require	O
the	O
use	O
of	O
executable	O
thunks	B-Application
,	O
so	O
they	O
do	O
not	O
share	O
this	O
weakness	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
blocks	O
introduces	O
a	O
completely	O
new	O
type	O
for	O
the	O
pointer	O
,	O
while	O
pointers	O
to	O
nested	O
functions	O
in	O
GCC	B-Application
are	O
regular	O
function	O
pointers	O
and	O
can	O
be	O
used	O
directly	O
with	O
existing	O
code	O
.	O
</s>
