From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id gAbMJS8wgWDJwQAAgWs5BA (envelope-from ) for ; Thu, 22 Apr 2021 10:13:35 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id mNyWIS8wgWDdCQAA1q6Kng (envelope-from ) for ; Thu, 22 Apr 2021 08:13:35 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D05809E2A for ; Thu, 22 Apr 2021 10:13:34 +0200 (CEST) Received: from localhost ([::1]:36734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZUSr-0002Gt-BA for larch@yhetil.org; Thu, 22 Apr 2021 04:13:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZUS6-00026z-8s for emacs-orgmode@gnu.org; Thu, 22 Apr 2021 04:12:46 -0400 Received: from smtp2-g21.free.fr ([2a01:e0c:1:1599::11]:36350) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZUS3-0005Fq-Dk for emacs-orgmode@gnu.org; Thu, 22 Apr 2021 04:12:46 -0400 Received: from [IPv6:2a01:e35:39f3:4610:e090:c3a5:d0c3:e596] (unknown [IPv6:2a01:e35:39f3:4610:e090:c3a5:d0c3:e596]) by smtp2-g21.free.fr (Postfix) with ESMTPS id 591AF20039E for ; Thu, 22 Apr 2021 10:12:40 +0200 (CEST) Subject: Re: Bug: Incompatible return type in org-babel C when using a table of doubles with a header as a variable [9.4.4 (release_9.4.4-272-ga9f38b @ /home/richard/.emacs.d/straight/build/org/)] To: emacs-orgmode@gnu.org References: From: tbanelwebmin Message-ID: Date: Thu, 22 Apr 2021 10:12:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Received-SPF: pass client-ip=2a01:e0c:1:1599::11; envelope-from=tbanelwebmin@free.fr; helo=smtp2-g21.free.fr X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619079214; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=of6ENvEEiHutOUq5K+N21wt8X8uefOP4X1f1LB6mQ6E=; b=mqGplF0ABJJ1kd815viLlL1FaGUMzt/Ggx54Kci2jiib1XlJBDhllJVlJvC52AXBu1k1ap jloxLeyJ23IFQ9ZxudGJmYPB7CM1W/A5hrkDIW0Es8/7oE3bT/MOlN2a7W+CQJCYkbNZBm wDq7GbB+N5yANl5bUQzTMGNteBl7+Knp7TMPF9Y0shm87TKlA0DN2h9NT+wcrY1bH0eXvT WFh3AnGxLDwwX7SclT4HZh0MDJZ1pNdRbXrIX3LNWKcHeyJ83cuchjzYn5FXHeeDwHO8/H iCdjg3/k6iRY5JxKgZRtDYQ3txlrfVRgkRGVlNzBx+OAv1HEiEUfpF1jMDD42g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619079214; a=rsa-sha256; cv=none; b=W+B02wkJGkeL4/Axn+AMHIbNfKsR+E1QVJbdLDvyP5pWs7oujHjQlh/CwEHQ8EAvVnM9Gd h2FmJudtZUT0di/VfKdMNGCWTpoZ0bcw6J6PEswIukoVyZ5oJcvuTtqFw9uIpxG2OJo60B ue7lu2EFp+t49DdLioc+KU188IUZAYk32BuhrMDnVZSqm+hTus7P4DpRjb1lk48fHAwbdl iATCCxu/GQjxCMAuaudlObTfJa3gfJmy8RhKs2yUAkmG9C+dD7V8DA7i85C/6q1PJ4uPmS D+VomufmejXQGcTyvn521pR/wXLMpieSypgd314vs7Pz0EIpzZmNINDnWcCzaA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=free.fr (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -2.34 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=free.fr (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: D05809E2A X-Spam-Score: -2.34 X-Migadu-Scanner: scn0.migadu.com X-TUID: cCVS3sYDBS+L I just pushed a patch. Your example works now. (Don't forget to change stdio.h into ).While waiting for the patch to be released, you can load this Lisp file: https://code.orgmode.org/bzg/org-mode/src/maint/lisp/ob-C.el Cheers Le 02/04/2021 à 19:40, Richard Sent via General discussions about Org-mode. a écrit : > When a table of floating pointer numbers that contains a header row is > set as a variable to a C source block, the generated header file > contains an invalid return type, causing the program to not compile. > > For example, if I have a table that looks like > > #+NAME: tbl-doubles-org-bug-report > #+begin_src C :includes :results table :colnames '("i" "val") >   for (int i = 0; i < 5; i++) { >     printf("%f %f\n", (double)i, i * 2.0); >   } > #+end_src > > #+RESULTS: tbl-doubles-org-bug-report > |   i | val | > |-----+-----| > | 0.0 | 0.0 | > | 1.0 | 2.0 | > | 2.0 | 4.0 | > | 3.0 | 6.0 | > | 4.0 | 8.0 | > > And then attempt to include that table as a variable called data > > #+begin_src C :includes stdio.h :var data=tbl-doubles-org-bug-report >   printf("No errors!"); > #+end_src > > Nothing is printed, and *Org-Babel Error Output* will display > > /tmp/babel-NQHi51/C-src-lsA892.c: In function ‘data_h’: > /tmp/babel-NQHi51/C-src-lsA892.c:24:65: error: incompatible types when > returning type ‘double’ but ‘const char *’ was expected >    24 | const char* data_h (int row, const char* col) { return > data[row][get_column_num(2,data_header,col)]; } >       |                                                        > ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > /bin/bash: line 1: /tmp/babel-NQHi51/C-bin-90Zk27: Permission denied > > If we look in the /tmp file mentioned, it's easy to see the > inconsistency. > > double data[5][2] = { > {0.000000,0.000000}, > {1.000000,2.000000}, > {2.000000,4.000000}, > {3.000000,6.000000}, > {4.000000,8.000000} > }; > const int data_rows = 5; > const int data_cols = 2; > int get_column_num (int nbcols, const char** header, const char* column) > { >   int c; >   for (c=0; c     if (strcmp(header[c],column)==0) >       return c; >   return -1; > } > const char* data_header[2] = {"i","val"}; > const char* data_h (int row, const char* col) { return > data[row][get_column_num(2,data_header,col)]; } > int main() { > printf("No errors!"); > return 0; > } > > data_h() should not return a const char*, but a double. > > I've also tested this with $ emacs -Q and the issue is still present. It > does not occur if the table contains integer values instead of floats > or if a header row is omitted. Seeing as how the header row is processed > differently from the data, I don't think the presence of a header row is > meant to cause this error. > > > > Emacs  : GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version > 3.24.22, cairo version 1.17.3) > of 2020-08-28 > Package: Org mode version 9.4.4 (release_9.4.4-272-ga9f38b @ > /home/richard/.emacs.d/straight/build/org/) > > current state: > ============== > (setq > org-src-mode-hook '(org-src-babel-configure-edit-buffer > org-src-mode-configure-edit-buffer doom-modeline-set-org-src-modeline) > org-link-shell-confirm-function 'yes-or-no-p > org-blank-before-new-entry '((heading . t) (plain-list-item . t)) > org-metadown-hook '(org-babel-pop-to-session-maybe) > org-clock-out-hook '(org-clock-remove-empty-clock-drawer) > org-html-format-inlinetask-function > 'org-html-format-inlinetask-default-function > org-odt-format-headline-function 'org-odt-format-headline-default-function > org-agenda-files '("~/org") > org-ascii-format-inlinetask-function 'org-ascii-format-inlinetask-default > org-startup-folded t > org-mode-hook '(#[0 "\301\211\207" [imenu-create-index-function > org-imenu-get-tree] 2] > #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook > org-show-all append local] 5] > #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook > org-babel-show-result-all append local] 5] > org-babel-result-hide-spec org-babel-hide-all-hashes turn-on-auto-fill > mixed-pitch-mode org-superstar-mode > highlight-parentheses-mode) > org-odt-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"] > org-archive-hook '(org-attach-archive-delete-maybe) > org-confirm-elisp-link-function 'yes-or-no-p > org-agenda-before-write-hook '(org-agenda-add-entry-text) > org-metaup-hook '(org-babel-load-in-session-maybe) > org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 > "\n\n(fn ENTRY)"] > org-adapt-indentation nil > org-latex-format-drawer-function #[514 "\207" [] 3 "\n\n(fn _ CONTENTS)"] > org-babel-pre-tangle-hook '(save-buffer) > org-file-apps '(("\\.pdf\\'" . emacs) (auto-mode . emacs) (directory . > emacs) ("\\.mm\\'" . default) ("\\.x?html?\\'" . default) > ("\\.pdf\\'" . default)) > org-tab-first-hook '(org-babel-hide-result-toggle-maybe > org-babel-header-arg-expand) > org-hide-leading-stars t > org-babel-load-languages '((C . t) (emacs-lisp . t)) > org-log-done 'time > org-superstar-leading-bullet 32 > org-ascii-format-drawer-function #[771 "\207" [] 4 "\n\n(fn NAME > CONTENTS WIDTH)"] > org-agenda-loop-over-headlines-in-active-region nil > org-occur-hook '(org-first-headline-recenter) > org-cycle-separator-lines 1 > org-export-before-processing-hook > '(org-blackfriday--reset-org-blackfriday--code-block-num-backticks) > org-cycle-hook '(org-cycle-hide-archived-subtrees > org-cycle-hide-drawers org-cycle-show-empty-lines >   org-optimize-window-after-visibility-change) > org-speed-command-hook '(org-speed-command-activate > org-babel-speed-command-activate) > org-clock-persist-file "/home/richard/.emacs.d/var/org/clock-persist.el" > org-superstar-leading-fallback 8229 > org-odt-format-inlinetask-function > 'org-odt-format-inlinetask-default-function > org-latex-prefer-user-labels t > org-babel-tangle-lang-exts '(("D" . "d") ("C++" . "cpp") ("emacs-lisp" > . "el") ("elisp" . "el")) > org-publish-timestamp-directory > "/home/richard/.emacs.d/var/org/timestamps/" > org-export-before-parsing-hook '(org-attach-expand-links) > org-id-locations-file "/home/richard/.emacs.d/var/org/id-locations.el" > org-confirm-shell-link-function 'yes-or-no-p > org-link-parameters '(("attachment" :follow org-attach-follow > :complete org-attach-complete-link) ("id" :follow org-id-open) >        ("eww" :follow org-eww-open :store org-eww-store-link) ("rmail" > :follow org-rmail-open :store org-rmail-store-link) >        ("mhe" :follow org-mhe-open :store org-mhe-store-link) >        ("irc" :follow org-irc-visit :store org-irc-store-link :export > org-irc-export) >        ("info" :follow org-info-open :export org-info-export :store > org-info-store-link) >        ("gnus" :follow org-gnus-open :store org-gnus-store-link) >        ("docview" :follow org-docview-open :export org-docview-export > :store org-docview-store-link) >        ("bibtex" :follow org-bibtex-open :store org-bibtex-store-link) >        ("bbdb" :follow org-bbdb-open :export org-bbdb-export :complete > org-bbdb-complete-link :store org-bbdb-store-link) >        ("w3m" :store org-w3m-store-link) ("file+sys") ("file+emacs") > ("shell" :follow org-link--open-shell) >        ("news" :follow #[514 "\301\300\302Q\"\207" ["news" > browse-url ":"] 6 "\n\n(fn URL ARG)"]) >        ("mailto" :follow #[514 "\301\300\302Q\"\207" ["mailto" > browse-url ":"] 6 "\n\n(fn URL ARG)"]) >        ("https" :follow #[514 "\301\300\302Q\"\207" ["https" > browse-url ":"] 6 "\n\n(fn URL ARG)"]) >        ("http" :follow #[514 "\301\300\302Q\"\207" ["http" > browse-url ":"] 6 "\n\n(fn URL ARG)"]) >        ("ftp" :follow #[514 "\301\300\302Q\"\207" ["ftp" browse-url > ":"] 6 "\n\n(fn URL ARG)"]) >        ("help" :follow org-link--open-help) ("file" :complete > org-link-complete-file) >        ("elisp" :follow org-link--open-elisp) ("doi" :follow > org-link--open-doi)) > org-latex-format-headline-function > 'org-latex-format-headline-default-function > org-latex-logfiles-extensions '("lof" "lot" "tex~" "aux" "idx" "log" > "out" "toc" "nav" "snm" "vrb" "dvi" "fdb_latexmk" "blg" "brf" "fls" > "entoc" "ps" "spl" "bbl") > org-link-elisp-confirm-function 'yes-or-no-p > org-latex-format-inlinetask-function > 'org-latex-format-inlinetask-default-function > org-html-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME > CONTENTS)"] > org-html-format-headline-function > 'org-html-format-headline-default-function > org-confirm-babel-evaluate nil > org-fontify-whole-block-delimiter-line nil > ) >