From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: C code block: no return values Date: Tue, 16 Apr 2013 12:45:27 -0600 Message-ID: <878v4ico1k.fsf@gmail.com> References: <516D73FD.8000206@mun.ca> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:35377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USAtP-0006tX-6D for emacs-orgmode@gnu.org; Tue, 16 Apr 2013 14:46:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1USAtJ-0001Qv-S4 for emacs-orgmode@gnu.org; Tue, 16 Apr 2013 14:46:10 -0400 Received: from mail-da0-x229.google.com ([2607:f8b0:400e:c00::229]:45955) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USAtJ-0001Pc-Ix for emacs-orgmode@gnu.org; Tue, 16 Apr 2013 14:46:05 -0400 Received: by mail-da0-f41.google.com with SMTP id p8so239871dan.14 for ; Tue, 16 Apr 2013 11:46:04 -0700 (PDT) In-Reply-To: <516D73FD.8000206@mun.ca> (Roger Mason's message of "Tue, 16 Apr 2013 13:23:33 -0230") 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: Roger Mason Cc: emacs-orgmode@gnu.org Roger Mason writes: > Hello, > > I'm working through examples in "A Multi-Language Computing Environment for > Literate Programming and Reproducible Research" by Shulte et al. J. > Stat. Software, 46/3, 2012. > > This example compiles but results are not returned to the Org-mode buffer: > ======================================================== > #+name: cocktail.c > #+begin_src C :noweb yes :tangle cocktail.c > #include > <> > <
> > #+end_src > > #+name: main > #+begin_src C > int main(int argc, char *argv[]) { > int lst[argc-1]; > int i; > for(i=1;i lst[i-1] = atoi(argv[i]); > sort(lst, argc-1); > for(i=1;i printf("%d ", lst[i-1]); > printf("\n"); > } > #+end_src > > #+name: cocktail-sort > #+begin_src C :noweb yes > void sort(int *a, unsigned int l) > { > int swapped = 0; > int i; > do { > for(i=0; i < (l-1); i++) { > <> > } > if ( swapped == 0 ) break; > swapped = 0; > for(i= l - 2; i >= 0; i--) { > <> > } > } while(swapped > 0); > } > #+end_src > > #+name: swap > #+begin_src C > if ( a[i] > a[i+1] ) { > int temp = a[i]; > a[i] = a[i+1]; > a[i+1] = temp; > swapped = 1; > } > #+end_src > > #+call: cocktail.c[:cmdline 8 7 6 3 2 4 78]() > =========================================== > > Running C-c on the "call" line above produces: > > =============================== > #+RESULTS: cocktail.c[:cmdline 8 7 6 3 2 4 78]() > ================================ > > The answers should be here. But they aren't. > > Thanks for any help. > > Roger > Hi Roger, Since the publication of that paper, the code block execution engine has begun checking the return value of the invoked program to ensure it exits with success before parsing the output. The C program in this example actually returns the value of the final printf, which is non-zero and looks like a return. To get this example working with the latest version of Org-mode, one needs to added a "return 0;" to the end of the last code block, yielding the following. #+name: main #+begin_src C int main(int argc, char *argv[]) { int lst[argc-1]; int i; for(i=1;i