emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: tbanelwebmin <tbanelwebmin@free.fr>
To: emacs-orgmode@gnu.org
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/)]
Date: Thu, 22 Apr 2021 10:12:38 +0200	[thread overview]
Message-ID: <b9d0a37c-778c-0e3c-22ec-f7d6d1d15e6f@free.fr> (raw)
In-Reply-To: <MXIew5H--3-2@tutamail.com>

I just pushed a patch. Your example works now. (Don't forget to change
stdio.h into <stdio.h>).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 <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\x10\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\x01\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 "\x01\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\302\x04Q\x02\"\207" ["news"
> browse-url ":"] 6 "\n\n(fn URL ARG)"])
>        ("mailto" :follow #[514 "\301\300\302\x04Q\x02\"\207" ["mailto"
> browse-url ":"] 6 "\n\n(fn URL ARG)"])
>        ("https" :follow #[514 "\301\300\302\x04Q\x02\"\207" ["https"
> browse-url ":"] 6 "\n\n(fn URL ARG)"])
>        ("http" :follow #[514 "\301\300\302\x04Q\x02\"\207" ["http"
> browse-url ":"] 6 "\n\n(fn URL ARG)"])
>        ("ftp" :follow #[514 "\301\300\302\x04Q\x02\"\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
> )
>



      parent reply	other threads:[~2021-04-22  8:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-02 17:40 Richard Sent via General discussions about Org-mode.
2021-04-06  7:49 ` tbanelwebmin
2021-04-22  8:12 ` tbanelwebmin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b9d0a37c-778c-0e3c-22ec-f7d6d1d15e6f@free.fr \
    --to=tbanelwebmin@free.fr \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).