<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) = &amp;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 &lt;themiwi@gmail.com&gt;</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 &lt;jed@59A2.org&gt;</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 &lt;cmake@cmake.org&gt;</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>
&gt; Michael Wild wrote:<br>
&gt;&gt;<br>
&gt;&gt; On 19. Nov, 2009, at 15:06 , Jed Brown wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt; Michael Wild wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Not sure I'd like that... Instead of being more expressive,
I &nbsp;<br>
&gt;&gt;&gt;&gt; think this<br>
&gt;&gt;&gt;&gt; would be very confusing.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; This is not a some magic beast coming out of functional &nbsp;<br>
&gt;&gt;&gt; languages. &nbsp;In<br>
&gt;&gt;&gt; fact, it's pretty hard to find a language that can't do this
sort of<br>
&gt;&gt;&gt; thing, even older Fortrans let you pass functions.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Jed<br>
&gt;&gt;<br>
&gt;&gt; Yes, but that's something completely different! It's not like
you're<br>
&gt;&gt; able to do (using your notation):<br>
&gt;<br>
&gt; (not my notation)<br>
&gt;<br>
&gt;&gt; set(&amp;tmp &amp;install)<br>
&gt;&gt; set(&amp;install &amp;add_executable)<br>
&gt;&gt; set(&amp;add_executable &amp;tmp)<br>
&gt;&gt;<br>
&gt;&gt; In C/C++ and to various extent in Fortran (depending on the &nbsp;<br>
&gt;&gt; version) you<br>
&gt;&gt; can pass around &quot;function pointers&quot;. This is _not_ a
function. &nbsp;<br>
&gt;&gt; There's<br>
&gt;&gt; no way of doing that in C/C++ or Fortran (that is, without using
ugly<br>
&gt;&gt; preprocessor magic).<br>
&gt;<br>
&gt; CMake is untyped where as C, for example, is statically typed and
only<br>
&gt; allows symbols to be defined once (C++ breaks this with templates,
but<br>
&gt; 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
&nbsp;<br>
statically typed. You can overload functions, but then it really is &nbsp;<br>
the same thing as the function signature is considered to be part of &nbsp;<br>
the name. Also templates do not change this, as the template &nbsp;<br>
parameters are part of the type name.<br>
<br>
&gt; In any case, you sure can do<br>
&gt;<br>
&gt; &nbsp;int (*Func)(int,int) = SomeFunction;<br>
&gt; &nbsp;int x = Func(5,6);<br>
&gt; &nbsp;int y = FoldL(Func,array,size,3);<br>
&gt;<br>
&gt; and so on.<br>
&gt;<br>
<br>
Sure, but you're not _renaming_ a function. You're just assigning the &nbsp;<br>
address of a function to a pointer which can then be used to invoke &nbsp;<br>
that function. It is _always_ clear that Func is a pointer to a &nbsp;<br>
function and not something else.<br>
<br>
&gt; Jed<br>
&gt;<br>
<br>
Anyways, I didn't want to get into a language-war, but rather voiced &nbsp;<br>
my dislike for such dubious flexibility. CMake is very domain-specific
&nbsp;<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 &nbsp;<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>