From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dov Grobgeld Subject: Re: org-babel-C-ensure-main-wrap fails unless I add exit(0) Date: Thu, 5 Apr 2012 21:07:43 +0300 Message-ID: References: <87lima8bxp.fsf@gmx.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0015175cd2b49537c604bcf26a8c Return-path: Received: from eggs.gnu.org ([208.118.235.92]:36625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFr6A-0001uY-S7 for emacs-orgmode@gnu.org; Thu, 05 Apr 2012 14:07:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFr67-0001DT-CA for emacs-orgmode@gnu.org; Thu, 05 Apr 2012 14:07:53 -0400 Received: from mail-bk0-f41.google.com ([209.85.214.41]:37580) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFr67-0001D1-1s for emacs-orgmode@gnu.org; Thu, 05 Apr 2012 14:07:51 -0400 Received: by bkwq16 with SMTP id q16so1843129bkw.0 for ; Thu, 05 Apr 2012 11:07:43 -0700 (PDT) In-Reply-To: <87lima8bxp.fsf@gmx.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: Eric Schulte Cc: emacs-orgmode --0015175cd2b49537c604bcf26a8c Content-Type: text/plain; charset=UTF-8 Sure. They should be equivalent. (In C++ return is prefered as it calls destructors. But anyone relying on this when using C++ in org-mode should imnsho get a permanent ban from ever using C/C++ ;-). Regards, Dov On Thu, Apr 5, 2012 at 17:56, Eric Schulte wrote: > Dov Grobgeld writes: > > > Oops. I sawthat I wrote "do not get any error" though I meant "do not > get > > any resulting output". > > > > Would this alternate version work (without requiring stdlib.h)? > > (defun org-babel-C-ensure-main-wrap (body) > "Wrap body in a \"main\" function call if none exists." > (if (string-match "^[ \t]*[intvod]+[ \t\n\r]*main[ \t]*(.*)" body) > body > (format "int main() {\n%s\nreturn(0);\n}\n" body))) > > Thanks, > > > > > On Wed, Apr 4, 2012 at 11:13, Dov Grobgeld > wrote: > > > >> When running a babel C session under Linux/gcc I do not get any error > >> unless I add exit(0) as part of the C-code snippet. For some to me not > >> understood reason my program exits with error code=4, which is caught by > >> org-babel-eval and the printed output is not inserted into my buffer . I > >> solved this by adding `#include ` and `exit(0);` as part of > >> org-babel-C-ensure-main-wrap . > >> > >> Should I prepare this as patch? > >> > >> Regards, > >> Dov > >> > >> > > -- > Eric Schulte > http://cs.unm.edu/~eschulte/ > --0015175cd2b49537c604bcf26a8c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Sure. They shoul= d be equivalent. (In C++ return is prefered as it calls destructors. But an= yone relying on this when using C++ in org-mode should imnsho get a permane= nt ban from ever using C/C++ ;-).

Regards,
Dov

On Thu, Apr 5,= 2012 at 17:56, Eric Schulte <eric.schulte@gmx.com> wrote:
Dov Grobgeld <dov.grobgeld@gmail.com> writes:

> Oops. I sawthat =C2=A0I wrote "do not get any error" though = I meant "do not get
> any resulting output".
>

Would this alternate version work (without requiring stdlib.h)?

(defun org-babel-C-ensure-main-wrap (body)
=C2=A0"Wrap body in a \"main\" function call if none exists= ."
=C2=A0(if (string-match "^[ \t]*[intvod]+[ \t\n\r]*main[ \t]*(.*)&quo= t; body)
=C2=A0 =C2=A0 =C2=A0body
=C2=A0 =C2=A0(format "int main() {\n%s\nreturn(0);\n}\n" body)))=

Thanks,

>
> On Wed, Apr 4, 2012 at 11:13, Dov Grobgeld <dov.grobgeld@gmail.com> wrote:
>
>> When running a babel C session under Linux/gcc I do not get any er= ror
>> unless I add exit(0) as part of the C-code snippet. For some to me= not
>> understood reason my program exits with error code=3D4, which is c= aught by
>> org-babel-eval and the printed output is not inserted into my buff= er . I
>> solved this by adding `#include <stdlib.h>` and `exit(0);` a= s part of
>> org-babel-C-ensure-main-wrap .
>>
>> Should I prepare this as patch?
>>
>> Regards,
>> Dov
>>
>>

--
Eric Schulte
http://cs.unm.= edu/~eschulte/

--0015175cd2b49537c604bcf26a8c--