<font size=2 face="sans-serif">I agree with Michael. C/C++ does not allow
you pass around functions. You can only pass around pointers to functions.</font>
<br>
<br><font size=2 face="sans-serif">Perhaps this line is confusing you:</font>
<br>
<br><tt><font size=2>int (*Func)(int,int) = SomeFunction;</font></tt>
<br>
<br><tt><font size=2>This is not assigning SomeFunction to Func. It's assigning
a pointer to SomeFunction to Func. It technically should be written as:</font></tt>
<br>
<br><tt><font size=2>int (*Func)(int,int) = &SomeFunction;</font></tt>
<br>
<br><tt><font size=2>But the compiler is helping you out, or hurting you
depending on the way you look at it.</font></tt>
<br>
<br><font size=2 face="sans-serif">---------------------------------------------------------<br>
Aaron Wright<br>
Software Engineer - DCS Group<br>
Schweitzer Engineering Laboratories, Inc.<br>
Pullman, WA 99163<br>
509-334-8087</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Michael Wild <themiwi@gmail.com></b>
</font>
<br><font size=1 face="sans-serif">Sent by: cmake-bounces@cmake.org</font>
<p><font size=1 face="sans-serif">11/19/2009 07:46 AM</font>
<td width=59%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif">Jed Brown <jed@59A2.org></font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td><font size=1 face="sans-serif">CMake List <cmake@cmake.org></font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Re: [CMake] functions as first class
objects</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><tt><font size=2><br>
On 19. Nov, 2009, at 15:44 , Jed Brown wrote:<br>
<br>
> Michael Wild wrote:<br>
>><br>
>> On 19. Nov, 2009, at 15:06 , Jed Brown wrote:<br>
>><br>
>>> Michael Wild wrote:<br>
>>><br>
>>>> Not sure I'd like that... Instead of being more expressive,
I <br>
>>>> think this<br>
>>>> would be very confusing.<br>
>>><br>
>>> This is not a some magic beast coming out of functional <br>
>>> languages. In<br>
>>> fact, it's pretty hard to find a language that can't do this
sort of<br>
>>> thing, even older Fortrans let you pass functions.<br>
>>><br>
>>> Jed<br>
>><br>
>> Yes, but that's something completely different! It's not like
you're<br>
>> able to do (using your notation):<br>
><br>
> (not my notation)<br>
><br>
>> set(&tmp &install)<br>
>> set(&install &add_executable)<br>
>> set(&add_executable &tmp)<br>
>><br>
>> In C/C++ and to various extent in Fortran (depending on the <br>
>> version) you<br>
>> can pass around "function pointers". This is _not_ a
function. <br>
>> There's<br>
>> no way of doing that in C/C++ or Fortran (that is, without using
ugly<br>
>> preprocessor magic).<br>
><br>
> CMake is untyped where as C, for example, is statically typed and
only<br>
> allows symbols to be defined once (C++ breaks this with templates,
but<br>
> you're supposed to be careful so that all definitions are equivalent).<br>
<br>
Although this is OT, I have to say that this is not true. C++ is still
<br>
statically typed. You can overload functions, but then it really is <br>
the same thing as the function signature is considered to be part of <br>
the name. Also templates do not change this, as the template <br>
parameters are part of the type name.<br>
<br>
> In any case, you sure can do<br>
><br>
> int (*Func)(int,int) = SomeFunction;<br>
> int x = Func(5,6);<br>
> int y = FoldL(Func,array,size,3);<br>
><br>
> and so on.<br>
><br>
<br>
Sure, but you're not _renaming_ a function. You're just assigning the <br>
address of a function to a pointer which can then be used to invoke <br>
that function. It is _always_ clear that Func is a pointer to a <br>
function and not something else.<br>
<br>
> Jed<br>
><br>
<br>
Anyways, I didn't want to get into a language-war, but rather voiced <br>
my dislike for such dubious flexibility. CMake is very domain-specific
<br>
language used to create build systems, not a general-purpose language.<br>
<br>
BTW, in the OP's particular case I would prefer to patch the upstream <br>
source without any voodoo.<br>
<br>
Michael<br>
<br>
_______________________________________________<br>
Powered by </font></tt><a href=www.kitware.com><tt><font size=2>www.kitware.com</font></tt></a><tt><font size=2><br>
<br>
Visit other Kitware open-source projects at </font></tt><a href=http://www.kitware.com/opensource/opensource.html><tt><font size=2>http://www.kitware.com/opensource/opensource.html</font></tt></a><tt><font size=2><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: </font></tt><a href=http://www.cmake.org/Wiki/CMake_FAQ><tt><font size=2>http://www.cmake.org/Wiki/CMake_FAQ</font></tt></a><tt><font size=2><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
</font></tt><a href=http://www.cmake.org/mailman/listinfo/cmake><tt><font size=2>http://www.cmake.org/mailman/listinfo/cmake</font></tt></a><tt><font size=2><br>
</font></tt>
<br>