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: Unnamed functions, functors or, more formally, function literals



On Fri, 15 Mar 2002, Robert Dewar wrote:

> I see insufficient value in anonymous functions. It seems like minor
> syntactic sugar, that in fact does not fit into C very well,
> so it is more like syntactic vinegar :-)


After two days that I was away, it seems that your discussion have 
diverged from what I was proposed initially. I must underline that 
there no closures are necessary: the function is defined inside some 
other function as if it was defined with a name in a file scope level 
just before the definition of current function. So, the body of the 
function is completely interchangeable: you can give it a name and 
move to file scope, and on contrary. This makes conversion to standard 
syntax a piece of cake: just elevate a body of the function at where 
all file scope objects are defined and you are done. I think this is 
a best definition, especially in light of worries about conversion 
into portable code and code reuse. No functional programming here, 
things are much easier :)

This is not a sintactical sugar, this reduces an overhead required 
from a programmer wanting to define a small anonymous function, and 
it, nevertheless, fits well into C, it even accurately follows from 
a current C standard (see my reply to Bo Thornsen).

I`m little tired and I know an outcome of our discussion. I`d like to 
resume why, as I understood, function literals cannot be currently 
integrated into GCC compiler, before the thread is closed.

1. This is a nonstandard feature. That, howewer, seems to be a 
consequence of latest developments of the C language, which we see 
from C99 standard. That means, it is very probably, that soon we will 
have function literals introduced into C standard. Until that time, 
it is undesirable for GCC to introduce this feature because of 
incompatibilities that may arise between standard definition of 
function literals and the one GCC supported. The preferred way 
function literals can come into GCC is through a new C standard.

2. There don`t seem to be many people who need this feature (which 
is a kind of surprise for me), so above stated portability problems 
can`t pay-off.

Paul




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