Richard, yourbug submission uncovered 3 problems. From minor to major: 1. Missing delimitersin your example change :includes stdio.h to :includes <stdio.h>
2. The function strcmp() is undefined A patch has already been committed to fix that, in early January. 3. A mess between char* and double in automatically generated code. This is a regression. I am investigating it. Stay connected for an update. Thanks for reporting! Cheers Thierry 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 <stdio.h> :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<nbcols; 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 > ) >