From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Banel Subject: Re: babel C, C++, D enhancement Date: Sat, 14 Jun 2014 00:07:43 +0200 Message-ID: <539B762F.90406@free.fr> References: <878urc0zmw.fsf@bzg.ath.cx> <874n1ryeq1.fsf@bzg.ath.cx> <87y4xgxu74.fsf@Rainer.invalid> <87r438uycj.fsf@bzg.ath.cx> <538BA215.2050305@free.fr> <877g4uezak.fsf@gmail.com> <5394C55B.7010906@free.fr> <87tx7vq955.fsf@gmail.com> <87ha3p8fq9.fsf@Rainer.invalid> 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]:35705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvZdW-0000Qf-Hn for emacs-orgmode@gnu.org; Fri, 13 Jun 2014 18:07:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WvZdS-00062F-U1 for emacs-orgmode@gnu.org; Fri, 13 Jun 2014 18:07:50 -0400 Received: from smtp6-g21.free.fr ([2a01:e0c:1:1599::15]:44595) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvZdS-00061o-OM for emacs-orgmode@gnu.org; Fri, 13 Jun 2014 18:07:46 -0400 Received: from [IPv6:2a01:e35:2e21:def0:7495:86a1:3f5b:714f] (unknown [IPv6:2a01:e35:2e21:def0:7495:86a1:3f5b:714f]) by smtp6-g21.free.fr (Postfix) with ESMTP id A973182277 for ; Sat, 14 Jun 2014 00:07:43 +0200 (CEST) In-Reply-To: <87ha3p8fq9.fsf@Rainer.invalid> 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 Thanks Achim for finding and fixing this bug. I do agree about fuzziness between int and float. My Emacs considers 2305843009213693951 as an integer, 2305843009213693952 too large to be an integer. My C++ compiler sees 4294967295 as an integer, 4294967296 as too large to fit an int. So Babel C++ may cause problem for large integers. I am not sure how we can fix this in any case. In the meantime, we can force large values to be declared as doubles by adding dot zero like this: #+BEGIN_SRC C++ :var large=3D9876543210 .0 printf ("%g", large); #+END_SRC Thierry Le 13/06/2014 08:51, Achim Gratz a =E9crit : > Eric Schulte writes: >> This new patch looks great, and the test suite passes locally. I've >> just applied it. > You also get a warning from the byte-compiler on something that is > clearly a bug. I think the fix should be: > > --8<---------------cut here---------------start------------->8--- > diff --git a/lisp/ob-C.el b/lisp/ob-C.el > index dd03fa7..a794e2a 100644 > --- a/lisp/ob-C.el > +++ b/lisp/ob-C.el > @@ -264,7 +264,7 @@ (defun org-babel-C-val-to-C-type (val) > (list > (if (equal org-babel-c-variant 'd) "string" "const char*") > "\"%s\"")) > - (t (error "unknown type %S" type))))) > + (t (error "unknown type %S" basetype))))) > (cond > ((integerp val) type) ;; an integer declared in the #+begin_src l= ine > ((floatp val) type) ;; a numeric declared in the #+begin_src line > --8<---------------cut here---------------end--------------->8--- > > The type determination is a tad optimistic, too. An Emacs integer may > or may not fit into C type "int" depending on how Emacs is compiled and > which compiler you are using. > > > Regards, > Achim.