emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob 3ddef6c853b7bd0c58489ba3ea852b4ee77e060f 4283 bytes (raw)
name: testing/examples/ob-C-test.org 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
 
#+Title: a collection of examples for ob-C tests
#+OPTIONS: ^:nil
* Simple tests
  :PROPERTIES:
  :ID:       fa6db330-e960-4ea2-ac67-94bb845b8577
  :END:
#+source: simple
#+begin_src cpp :includes "<iostream>" :results silent
  std::cout << 42;
  return 0;
#+end_src

#+source: simple
#+begin_src cpp :includes <iostream> :results silent
  std::cout << 42;
  return 0;
#+end_src

#+source: simple
#+begin_src D :results silent
  writefln ("%s", 42);
#+end_src

#+source: integer_var
#+begin_src cpp :var q=12 :includes "<iostream>" :results silent
  std::cout << q;
  return 0;
#+end_src

#+source: integer_var
#+begin_src D :var q=12 :results silent
  writefln ("%s", q);
#+end_src

#+source: two_var
#+begin_src cpp :var q=12 :var p=10 :includes "<iostream>" :results silent
  std::cout << p+q;
  return 0;
#+end_src

#+source: two_var
#+begin_src D :var q=12 :var p=10 :results silent
  writefln ("%s", p+q);
#+end_src

#+source: string_var
#+begin_src cpp :var q="word" :includes '(<iostream> <cstring>) :results silent
  std::cout << q << ' ' << std::strlen(q);
  return 0;
#+end_src

#+source: string_var
#+begin_src D :var q="word" :results silent
  writefln ("%s %s", q, q.length);
#+end_src

#+source: define
#+begin_src cpp :defines N 42  :includes "<iostream>" :results silent
  std::cout << N;
  return 0;
#+end_src

* Array
  :PROPERTIES:
  :ID:       2df1ab83-3fa3-462a-a1f3-3aef6044a874
  :END:
#+source: array
#+begin_src cpp :includes "<iostream>" :results vector :results silent
  for (int i=1; i<3; i++) {
    std::cout << i << '\n';
  }
  return 0;
#+end_src

#+source: array
#+begin_src D :results vector :results silent
  foreach (i; 1..3)
    writefln ("%s", i);
#+end_src

* Matrix
  :PROPERTIES:
  :ID:       cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5
  :END:
#+name: C-matrix
| 1 | 2 |
| 3 | 4 |

#+source: list_var
#+begin_src cpp :var a='("abc" "def") :includes "<iostream>" :results silent
  std::cout << a[0] << a[1] << sizeof(a)/sizeof(*a) << '\n';
#+end_src

#+source: list_var
#+begin_src D :var a='("abc" "def") :results silent
  writefln ("%s%s%s", a[0], a[1], a.length);
#+end_src

#+source: vector_var
#+begin_src cpp :var a='[1 2] :includes "<iostream>" :results silent
  std::cout << a[0] << a[1] << sizeof(a)/sizeof(*a) << '\n';
#+end_src

#+source: vector_var
#+begin_src D :var a='[1 2] :results silent
  writefln ("%s%s%s", a[0], a[1], a.length);
#+end_src

#+source: list_list_var
#+begin_src cpp :var q=C-matrix :includes "<iostream>" :results silent
  std::cout << q[0][0] << ' ' << q[1][0] << '\n'
            << q[0][1] << ' ' << q[1][1] << '\n'; // transpose
#+end_src

#+source: list_list_var
#+begin_src D :var q=C-matrix :results silent
  writefln ("%s %s", q[0][0], q[1][0]);
  writefln ("%s %s", q[0][1], q[1][1]); // transpose
#+end_src

* Inhomogeneous table
  :PROPERTIES:
  :ID:       e112bc2e-419a-4890-99c2-7ac4779531cc
  :END:

#+name: tinomogen
  | day       | quty |
  |-----------+------|
  | monday    |   34 |
  | tuesday   |   41 |
  | wednesday |   56 |
  | thursday  |   17 |
  | friday    |   12 |
  | saturday  |    7 |
  | sunday    |    4 |

#+source: inhomogeneous_table
#+begin_src cpp :var tinomogen=tinomogen :results silent :includes <string.h> <stdio.h>
int main()
{
  int i, j;
  for (i=0; i<tinomogen_rows; i++) {
    for (j=0; j<tinomogen_cols; j++)
      printf ("%s ", tinomogen[i][j]);
    printf ("\n");
  }
  printf ("Friday %s\n", tinomogen_h(4,"day"));
  return 0;
}
#+end_src

#+source: inhomogeneous_table
#+begin_src D :var tinomogen=tinomogen :results silent
import std.stdio;
void main()
{
  for (int i=0; i<tinomogen_rows; i++) {
    for (int j=0; j<tinomogen_cols; j++)
      writef ("%s ", tinomogen[i][j]);
    writeln();
  }
  writefln ("Friday %s", tinomogen_h(4,"day"));
}
#+end_src

* Output
:PROPERTIES:
:ID:       9386490b-4063-4400-842c-4a634edbedf5
:END:

#+source: double_quotes
#+begin_src cpp :includes <iostream> :results output verbatim raw
std::cout << "\"line 1\"\n";
std::cout << "\"line 2\"\n";
std::cout << "\"line 3\"\n";
#+end_src

* File naming
:PROPERTIES:
:ID:       1a691f36-f9c1-4531-8fc0-ee7b21ef5975
:END:

#+source: file_naming
#+begin_src cpp :includes <iostream> :results output raw drawer :file ./hello-world
std::cout << "Hello World!\n";
#+end_src

debug log:

solving 1a104ae6a ...
found 1a104ae6a in https://list.orgmode.org/orgmode/87fs81egk5.fsf@t14.reltub.ca/
found c7a96f665 in https://git.savannah.gnu.org/cgit/emacs/org-mode.git
preparing index
index prepared:
100644 c7a96f665242ba73105433fcadb8a7154aded5a4	testing/examples/ob-C-test.org

applying [1/1] https://list.orgmode.org/orgmode/87fs81egk5.fsf@t14.reltub.ca/
diff --git a/testing/examples/ob-C-test.org b/testing/examples/ob-C-test.org\r
index c7a96f665..1a104ae6a 100644\r

Checking patch testing/examples/ob-C-test.org...
Applied patch testing/examples/ob-C-test.org cleanly.

index at:
100644 3ddef6c853b7bd0c58489ba3ea852b4ee77e060f	testing/examples/ob-C-test.org

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).