Commit 49877ddc authored by ROUVREAU Vincent's avatar ROUVREAU Vincent Committed by GILLES Sebastien
Browse files

Remove semicolon at the end of function declaration, and explains why it is...

Remove semicolon at the end of function declaration, and explains why it is required to add a semicolon at the end of a struct
parent c10a1de3
......@@ -43,7 +43,7 @@
"double norm(double v_x, double v_y, double v_z) \n",
"{ \n",
" return std::sqrt( v_x * v_x + v_y * v_y + v_z * v_z ); \n",
"};\n",
"}\n",
"\n",
"{\n",
" double v1_x, v1_y, v1_z;\n",
......@@ -158,6 +158,41 @@
"Let's also highlight the `.` syntax which allows to access the attributes of an object (e.g `v1.x`).\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### The semicolon at the end of a `struct`\n",
"This comes historically from the C, where a `struct` is considered as a type declaration and it allows to do:\n",
"\n",
"**Xeus-cling issue:** Here cling doesn't manage to compile it but it is accepted rightfully by a full-fledged compiler (see for instance [@Coliru](http://coliru.stacked-crooked.com/a/3b77606ea8082485)):"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"struct Vector\n",
"{\n",
" double x;\n",
" double y;\n",
" double z; \n",
"} v1; // Here the struct is declared and at the same time an object v1 is created\n",
"\n",
"v1.x = 1.;\n",
"v1.y = 5.;\n",
"v1.z = -2.;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is the reason why a semicolon is always required at the end of a `struct` or a `class` declaration."
]
},
{
"cell_type": "markdown",
"metadata": {},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment