Symbol Quick Reference
This is a table for checking the meaning of symbols and keywords while you read MISO’s code in the C++ chapters (Chapters 2–6) and in Chapters 7–9. You do not need to read it through. From the “Details” column of each row, you can go back to the chapter in the main text.
Contents
Basics of reading: declaration or expression?
In C++, the same symbol means different things in a declaration (a statement that creates a new name) and in an expression (a computation that uses an existing name). When you are unsure about a symbol, first check whether the line is creating a name or using one.
double a = 1.0;
double *p = &a; // * in a declaration: p is a "pointer to double". & in an expression: address of a
*p = 2.0; // * in an expression: write 2.0 to what p points to (a)
double &r = a; // & in a declaration: r is an alias (reference) of a
In the tables below, read a and b as double variables, p as a pointer of type double *, and T as a template argument type.
* and & and &&
Form you see |
Declaration or expression |
Meaning |
Details |
|---|---|---|---|
|
Declaration |
|
|
|
Expression |
Reads and writes the value that |
|
|
Expression |
Multiplication |
|
|
Declaration |
|
|
|
Declaration (parameter) |
Pass by reference. If you change |
|
|
Declaration (parameter) |
Pass by reference for reading only. It does not copy and does not modify |
|
|
Expression |
Takes the address of |
|
|
Expression |
An expression that points to member |
|
|
Expression |
Logical AND (and). It is Fortran’s |
|
|
Declaration (parameter) |
An rvalue reference. It is used to receive a move (a transfer of contents) |
|
|
Declaration |
Forbids modification through |
|
|
Declaration |
Forbids switching what |
|
|
Declaration (member) |
A pointer to the start of the array, held by |
|
|
Declaration (parameter) |
A pointer to a pointer. You see it in the command-line arguments of |
MISO’s source attaches * and & to the name, as in double *p (the .clang-format setting). double* p and double *p mean the same thing.
Symbols that refer to names and members (:: . ->)
Form you see |
Meaning |
Details |
|---|---|---|
|
A name inside a namespace. |
|
|
A type inside the namespace |
|
|
A leading |
|
|
A name belonging to a class (a |
|
|
A member of the template argument |
|
|
Uses a member of an object (or reference) |
|
|
Uses a member of what the pointer |
|
|
Inside a member function, uses a member through |
Brackets (<> [] () {})
Form you see |
Meaning |
Details |
|---|---|---|
|
Includes a header in a fixed location, such as the standard library |
|
|
Looks for a header relative to the location of your own file and includes it |
|
|
Comparison, bit shift, and output |
|
|
Template arguments. The angle brackets are part of the type name, forming a single name |
|
|
Declares the name of a type to be decided later |
|
|
A full specialization (a definition in which all template arguments are fixed) |
|
|
Uses a variable template or function template by specifying a type |
|
|
Converts |
|
|
A launch of a CUDA kernel. It is not a C++ symbol |
|
|
An element of an array or |
|
|
|
|
|
Allocating and freeing an array |
|
|
The definition of an operator that lets you write |
|
|
The start of a lambda expression (an unnamed function). |
|
|
A function call |
|
|
|
|
|
Reading and writing an array element through |
|
|
The definition of an operator that lets you write |
|
|
|
|
|
Parentheses that determine the order of computation |
|
|
A group of statements (a block). A variable declared inside ends its lifetime at |
|
|
The body of a class. |
|
|
Initialization with braces |
|
|
An expression that creates a value of a type without an initial value. Used to pass a tag type to a function |
|
|
The member initializer list of a constructor (written between |
The distinction between <...> and (...) is important. In Array3D<float> a(4, 4, 4);, float specifies a type, and 4, 4, 4 are the values passed to the constructor.
Other operators
Form you see |
Meaning |
Details |
|---|---|---|
|
Assignment. Comparison is |
|
|
Equal and not equal (Fortran’s |
|
|
Logical OR (or) and negation (Fortran’s |
|
|
The remainder of integer division (Fortran’s |
|
|
Increases |
|
|
The same as |
|
|
|
|
|
The name of the destructor (a cleanup function) |
|
|
A specifier written in place of a function body. It makes the compiler provide the function or makes it unusable |
|
|
|
Preprocessor symbols (#)
Lines that start with # are processed by the preprocessor before compilation. This is text replacement, separate from C++ grammar.
Form you see |
Meaning |
Details |
|---|---|---|
|
Includes the contents of a file at that place |
|
|
Prevents the same header from being included twice |
|
|
Defines a macro that replaces |
|
|
Selects the part to compile depending on whether a macro is defined. It is the same as Fortran’s |
|
|
A part that is active only when building with the CUDA compiler (nvcc) |
|
|
Cancels the definition of a macro |
|
|
Continues the macro definition onto the next line |
|
|
Joins the parts before and after into a single name ( |
|
|
Turns the argument into a string ( |
Keywords
This collects mainly those whose meaning changes depending on their position in a declaration.
Keywords |
Form you see and its meaning |
Details |
|---|---|---|
|
|
|
|
||
|
||
|
||
|
||
|
|
|
|
|
|
|
|
|
|
||
|
||
|
|
|
|
||
|
||
|
|
|
|
||
|
Attached to ordinary functions and variables whose definitions are placed in a header. It is not a specifier for making things faster |
|
|
Inside a class, a member that belongs to the class regardless of any object |
|
|
Forbids implicit type conversion by a constructor |
|
|
Indicates that the function does not let exceptions escape |
|
|
A virtual function whose derived-class version is chosen at run time. MISO does not use it |
|
|
Determines the type of an expression without evaluating it |
|
|
A branch whose condition is determined at compile time. The side not selected is not included |
|
|
Makes it a compile error if the condition is false |
|
|
A pointer that points nowhere |
|
|
Inside a member function, a pointer to itself. Using it inside a lambda causes problems on the GPU |
|
|
A class declaration. |
MISO and CUDA symbols
These are not C++ keywords, but names provided by MISO and CUDA.
Form you see |
Meaning |
Details |
|---|---|---|
|
The floating-point type that the demos fix with |
|
|
Tag types that represent the place of computation and memory ( |
|
|
A macro that marks the start of a lambda expression. In a CPU build it is |
|
|
A specifier for whether a function can be called from the CPU or the GPU. It is empty in a CPU-only build ( |
|
|
A specifier for a kernel function that runs on the GPU |
|
|
Types and functions of the MPI library |
Order of checks when reading a declaration
Read a long declaration by splitting it up in the following order.
Find the name. Check whether it declares a variable, a function, or a type.
Read the type. The type includes everything up to
<...>. Iftemplate <...>comes before, the names inside the angle brackets are types decided later.Distinguish value, reference, and pointer. Look at whether
&or*is attached to the name.Check what
constapplies to. Distinguish whether it is the value, what is pointed to, the pointer itself, or the member function.Check how it is created and its lifetime. Trace which objects the initial value, parameters, and return value use, and how long they remain usable.
As an example, let us read a declaration from miso/include/miso/mhd_integrator.hpp in parts.
template <typename Real, typename Source>
__host__ __device__ inline Real source_vx(const Source &src,
const FieldsView<const Real> &qq,
int i, int j, int k);
Part |
How to read it |
|---|---|
|
|
|
A function that can be called from both the CPU and the GPU |
|
A function placed in a header |
|
The name is |
|
Receives the source-term object as a reference for reading only |
|
Receives a view that only reads the elements ( |
|
Receives the grid-point indices by value |
For the details of the grammar, see the C++17 draft standard N4659: declaring references, the rules for const, and templates.