5
|
1 {
|
|
2 "cells": [
|
|
3 {
|
|
4 "cell_type": "markdown",
|
|
5 "metadata": {},
|
|
6 "source": [
|
|
7 "# Valid code"
|
|
8 ]
|
|
9 },
|
|
10 {
|
|
11 "cell_type": "code",
|
|
12 "execution_count": 1,
|
|
13 "metadata": {
|
|
14 "collapsed": false
|
|
15 },
|
|
16 "outputs": [
|
|
17 {
|
|
18 "name": "stderr",
|
|
19 "output_type": "stream",
|
|
20 "text": []
|
|
21 },
|
|
22 {
|
|
23 "name": "stdout",
|
|
24 "output_type": "stream",
|
|
25 "text": [
|
|
26 "Hello world\n"
|
|
27 ]
|
|
28 }
|
|
29 ],
|
|
30 "source": [
|
|
31 "#include <stdio.h>\n",
|
|
32 "\n",
|
|
33 "int main() {\n",
|
|
34 " printf(\"Hello world\\n\");\n",
|
|
35 "}"
|
|
36 ]
|
|
37 },
|
|
38 {
|
|
39 "cell_type": "markdown",
|
|
40 "metadata": {},
|
|
41 "source": [
|
|
42 "But the kernel will also display compilations warnings and errors if we have some. Let's try to remove the `#include <stdio.h>` statement, which if necessary for `printf` to work."
|
|
43 ]
|
|
44 },
|
|
45 {
|
|
46 "cell_type": "markdown",
|
|
47 "metadata": {},
|
|
48 "source": [
|
|
49 "# Code generating warnings during compilation"
|
|
50 ]
|
|
51 },
|
|
52 {
|
|
53 "cell_type": "code",
|
|
54 "execution_count": 2,
|
|
55 "metadata": {
|
|
56 "collapsed": false
|
|
57 },
|
|
58 "outputs": [
|
|
59 {
|
|
60 "name": "stderr",
|
|
61 "output_type": "stream",
|
|
62 "text": [
|
|
63 "/var/folders/31/qct57s856n5f0b2r4tgbmn1c0000gn/T/tmp0Qan0v.c:2:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]\n",
|
|
64 " printf(\"Hello world\\n\");\n",
|
|
65 " ^\n",
|
|
66 "/var/folders/31/qct57s856n5f0b2r4tgbmn1c0000gn/T/tmp0Qan0v.c:2:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'\n",
|
|
67 "1 warning generated.\n"
|
|
68 ]
|
|
69 },
|
|
70 {
|
|
71 "name": "stdout",
|
|
72 "output_type": "stream",
|
|
73 "text": [
|
|
74 "Hello world\n"
|
|
75 ]
|
|
76 }
|
|
77 ],
|
|
78 "source": [
|
|
79 "int main() {\n",
|
|
80 " printf(\"Hello world\\n\");\n",
|
|
81 "}"
|
|
82 ]
|
|
83 },
|
|
84 {
|
|
85 "cell_type": "markdown",
|
|
86 "metadata": {},
|
|
87 "source": [
|
|
88 "You can see that the warning are displayed, but the code is still executed."
|
|
89 ]
|
|
90 },
|
|
91 {
|
|
92 "cell_type": "markdown",
|
|
93 "metadata": {},
|
|
94 "source": [
|
|
95 "# Code generating errors during compilation"
|
|
96 ]
|
|
97 },
|
|
98 {
|
|
99 "cell_type": "code",
|
|
100 "execution_count": 3,
|
|
101 "metadata": {
|
|
102 "collapsed": false
|
|
103 },
|
|
104 "outputs": [
|
|
105 {
|
|
106 "name": "stderr",
|
|
107 "output_type": "stream",
|
|
108 "text": [
|
|
109 "/var/folders/31/qct57s856n5f0b2r4tgbmn1c0000gn/T/tmpw4Kz3c.c:2:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]\n",
|
|
110 " printf(\"Hello world\")\n",
|
|
111 " ^\n",
|
|
112 "/var/folders/31/qct57s856n5f0b2r4tgbmn1c0000gn/T/tmpw4Kz3c.c:2:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'\n",
|
|
113 "/var/folders/31/qct57s856n5f0b2r4tgbmn1c0000gn/T/tmpw4Kz3c.c:2:26: error: expected ';' after expression\n",
|
|
114 " printf(\"Hello world\")\n",
|
|
115 " ^\n",
|
|
116 " ;\n",
|
|
117 "1 warning and 1 error generated.\n",
|
|
118 "[C kernel] GCC exited with code 1, the executable will not be executed"
|
|
119 ]
|
|
120 },
|
|
121 {
|
|
122 "name": "stdout",
|
|
123 "output_type": "stream",
|
|
124 "text": []
|
|
125 }
|
|
126 ],
|
|
127 "source": [
|
|
128 "int main() {\n",
|
|
129 " printf(\"Hello world\")\n",
|
|
130 "}"
|
|
131 ]
|
|
132 },
|
|
133 {
|
|
134 "cell_type": "markdown",
|
|
135 "metadata": {},
|
|
136 "source": [
|
|
137 "You can see that the errors and warnings are shown, but the code is not executed. The retcode is also added to the end of `stderr`"
|
|
138 ]
|
|
139 }
|
|
140 ],
|
|
141 "metadata": {
|
|
142 "kernelspec": {
|
|
143 "display_name": "C",
|
|
144 "language": "c",
|
|
145 "name": "c_kernel"
|
|
146 },
|
|
147 "language_info": {
|
|
148 "file_extension": "c",
|
|
149 "mimetype": "text/plain",
|
|
150 "name": "c"
|
|
151 }
|
|
152 },
|
|
153 "nbformat": 4,
|
|
154 "nbformat_minor": 0
|
|
155 }
|