From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Banel Subject: Re: babel: ob-C with Visual C++ and compilation-mode Date: Thu, 14 Aug 2014 22:40:16 +0200 Message-ID: <53ED1EB0.3030500@free.fr> References: <878un4ut6c.fsf@gmail.com> <53E91C32.4000002@free.fr> <87lhqt6b0w.fsf@gmail.com> <53EA8F2B.7010205@free.fr> <87zjf8cdjk.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XI1op-0008FH-Be for emacs-orgmode@gnu.org; Thu, 14 Aug 2014 16:40:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XI1oo-0006jp-Bb for emacs-orgmode@gnu.org; Thu, 14 Aug 2014 16:40:19 -0400 Received: from smtp3-g21.free.fr ([2a01:e0c:1:1599::12]:32403) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XI1oo-0006jZ-5r for emacs-orgmode@gnu.org; Thu, 14 Aug 2014 16:40:18 -0400 Received: from [IPv6:2a01:e35:2e21:def0:4433:9b88:ade2:4c10] (unknown [IPv6:2a01:e35:2e21:def0:4433:9b88:ade2:4c10]) by smtp3-g21.free.fr (Postfix) with ESMTP id 87F06A61B0 for ; Thu, 14 Aug 2014 22:40:16 +0200 (CEST) In-Reply-To: <87zjf8cdjk.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Le 13/08/2014 22:58, Ernesto Durante a =E9crit : > Thank you Thierry for your answer and all the details. I really want to= be a contributor > and help ob-C to improve (as well as can do a modest lisper). Any help is welcome ! > I tried to find a way to master Cx11 and babel is helping me a lot. > I think babel can really accelerate learning and dissimation of C++. > > In this perspective, I have another very simple idea that I want to sha= re > with you. I find C++ too noisy.=20 Yes, indeed. > In the following piece of code > I really find the presence of the main call and the return statement re= ally annoying and useless. > > #+begin_src C++ :includes '( ) :results silent > template > auto compose(T1 t1, T2 t2) -> decltype(t1 + t2) { return t1+t2; } > > int main() { > auto d=3Dcompose(std::string("ola"),std::string("ciao")); //d's type i= s std::string > auto i=3Dcompose(4,2); > assert(d=3D=3D std::string("olaciao") && i=3D=3D6); > return 0 > } > #+end_src > > We can remove it by letting ob-C do the work by modifying the function > org-babel-C-ensure-main-wrap. Now the code looks (according to me) easi= er to read > > #+begin_src C++ :includes '( ) :results silent > template > auto compose(T1 t1, T2 t2) -> decltype(t1 + t2) { return t1+t2; } > > template <> > int compose(int t1,int t2) { return t1+t2; } > > ////main//// > auto d=3Dcompose(std::string("ola"),std::string("ciao")); //d's type is= std::string > auto i=3Dcompose(4,2); > assert(d=3D=3D std::string("olaciao") && i=3D=3D6); > #+end_src > > What do you think ? > > Well... In this example, we go down from 9 lines to 7 lines. Ok fair. But the price is a new syntax to learn: ////main//// Is it wise to add an org-mode specific syntax to C++ (which already has a lot) ? Being noisy is a weakness of C++. I think it is not the responsibility of org-mode to fix that. Now, org-mode is already able to process main()-less blocks in simple cas= es. #+BEGIN_SRC C++ printf("hello\n"); #+END_SRC If we can find a way to extend this feature to more cases, without needing a long documentation, then, sure, it would be a nice improvement. Regards Thierry