NMBU REALTEK, INF205, 2022 høst: Glossary
Allocation
(under construction)
See also: Deallocation, pointer, rule of five.
Boolean variable
Definition: A Boolean variable is a variable that can hold the values true and false.
- C/C++ uses the fundamental data type bool for Boolean variables.
- This is an integer-like data type, usually with a size of one byte, where 0 is read as false; any other value is read as true, but by default, true is mapped to 1.
Compilation
Definition: Compilation (or compiling) is the process of transforming a human-readable source code into a lower-level machine code. It is done by a compiler.
- In C/C++, the compiler is only run on the source files; in C++, these files usually have the file ending *.cpp, *.cxx, or *.C. The compiler is not run on the header files (usually with a *.h file ending).
- The machine code created by compiling a source file with a C/C++ compiler is called object code; it is stored as an object file, which usually has a *.o file ending.
- The object files produced by compiling are not executable by themselves: They need to be linked into one standalone executable file.
See also: Linking.
Concurrency
Definition: Two operations are concurrent if they can be parallelized.
- In the framework of discrete event systems, two events t and u are concurrent if all of the following hold: Both t and u are enabled (they can both occur) and they are not causally dependent, i.e., they do not disable each other, and whichever order they occur in, tu or ut, the outcome wull be the same.
- The maximum possible parallel speedup in strong scaling, based on the fraction of the work to be done that is concurrent or non-concurrent (inherently sequential), is given by Amdahl's law.
See also: Discrete event system, strong scaling.
Container
Definition (Stroustrup, 2018, p. 137): "A class with the main purpose of holding objects is commonly called a container."
- Examples include the standard template library (STL) containers (list, map, set, vector, etc.). Other than for educational purposes as an exercise, it does not make sense to reimplement these standard data structures by hand.
- Many problems require special, tailored container data structures in order to be solved efficiently. It is then part of the development work to both design and implement the required data structure.
See also: Graph, queue.
Deallocation
(under construction)
See also: Allocation, pointer.
Dereferencing
Definition: Referencing is the act of accessing the data stored at a given memory address. In C++ this is done using the * operator: *y is the data item stored at the address y.
- Referencing and dereferencing are inverse operations. If x is a variable, *(&x) is the same as x.
- Pointers need to be dereferenced explicitly, using the * operator. In the case of a reference, this is not needed: It is dereferenced implicitly, and the memory address remains unaccessible to the programmer.
See also: Pointer, reference, referencing.
Discrete event system
See also: Concurrency
Function
Definition: A function is a block of code that can be called with parameters.
- A function (also called a procedure) is the main and highest-level control flow structure employed in procedural programming.
- Parameters are the names of the variables passed to the function, arguments are the values associated with these parameters. There are two main ways of passing an argument to a function: By value and by reference.
- A function can also return a value (the return value of the function); the type of that value is the function's return type. In C/C++, if a function does not return a value, its return type needs to be specified as void.
See also: Pass by reference, pass by value, procedural programming, return value, void.
Global variable
Definition: A global variable is a variable that can be accessed through a name with an unrestricted scope. It has a name that resolves everywhere in the code.
- It is a good idea to use namespaces to provide some structure to the set of names that are accessible globally.
- The term local variable can sometimes refer to any variable that is not global (i.e., any variable with a restricted scope). But it is more common to just call those variables "local" that are declared within a function; these are the variables that are stored in memory on the stack, in the stack frame corresponding to that function.
- Some say that it is bad style to use any global variables at all; the Core Guidelines allow them as part of the recommended style, but they must be constant (rule I.2). The main reason is that it is hard to debug or verify what a code does if it relies on write access to global variables.
See also: Namespace, procedural programming, scope.
Graph
Definition: A graph is a container data structure consisting
of nodes (also called vertices) and edges;
an edge is a connection between two nodes.
- In a labelled graph, nodes and/or edges can carry labels, which can be numbers, strings, or any other data items.
- In a directed graph, each edge has a direction; there, an edge only serves as a link from its source node to its target node. In an undirected graph, the edges do not have a direction; there, an edge serves as a link between its two incident nodes, going both ways.
- A sequence of edges, where the target of one edge is the source of the next one, is called a path.
- A directed graph is a tree (also: out-tree) if it has a unique root node and a unique path from the root to each node.
See also: Container.
Heap
(under construction)
Linking
(under construction)
See also: Compilation.
Method
Definition: A method is a function that is declared as part of a class definition. Each method call it carried out for an individual object that instantiates this class.
Namespace
Definition: A namespace is a subset of all the names that can be accessed globally, i.e., from anywhere in the source code.
- To access name Y defined in namespace X, we write X::Y.
- With using namespace X; all the names from X can be accessed without a prefix.
See also: Global variable, scope.
Pass by reference
(under construction)
See also: Function, pass by value, pointer, reference.
Pass by value
Summary: When an argument is passed by value to a function, a copy of the argument values is created in memory (on the stack, in the stack frame of the called function). The function works with its own copy; it cannot access the original variable.
See also: Function, pass by reference.
Queue
A queue is a sequential (list-like) dynamic data structure
that functions by the principle first in, first out (FIFO).
It has a method for appending an element, usually called push and
done on one end of the queue (e.g., push_back), and a method for detaching an element,
usually called pop and done at the other end of the queue (e.g., pop_front).
- Singly and doubly linked lists are well suitable for
implementing a queue, since both push and pop
can be realized in constant time. However, a singly linked
list should only be used if the data structure includes an explicit
reference to the tail node; otherwise, the whole list needs to
be traversed just to reach the tail, taking O(n) time.
- Dynamic arrays are less suitable for this purpose, requiring
O(n) time for the push and pop
operations in the long run (as their capacity gets exhausted).
See also: Container.
Pointer
Definition: A pointer is a variable that has a memory address as its value.
See also: Allocation, dereferencing, pass by reference, reference, referencing, void.
Procedural programming
Definition: Procedural programming is the programming paradigm where procedures (called functions in C/C++) are employed as the highest-level device for structuring code and the program control flow.
See also: Function, global variable, return value.
Reference
Definition: A reference is an alias for the data item stored at a given memory address; the address remains hidden from the programmer, who can use the reference as if it was the data item itself.
- A reference, with the name z, for variable y of type Y is declared and initialized as follows: Y& z = y; From now on, z and y can be used interchangeably.
- Theoretically it is possible to use references anywhere in the code, for any purpose; they are equivalent in functionality to pointer. But in practice they are rarely used for anything other than passing a function argument by reference.
- Upon accessing a reference, implicit dereferencing occurs. Example: int& z = y; cout << z; This will print out the value of y. This stands in contrast to pointers, where explicit dereferencing using the operator "*" would be needed: int* x = y; cout << *x;
See also: Dereferencing, pass by reference, pointer.
Referencing
Definition: Referencing is the act of obtaining the address of a variable. In C++ this is done using the & operator: &x is the address of x.
See also: Dereferencing, pointer.
Return value
Definition: Value returned by a called function to the function from which it was called; in C/C++ and most other languages that support procedural programming, this is done through a return statement. The function call in the calling function then resolves (i.e., evaluates) to the return value.
See also: Function, procedural programming, void.
Rule of five
Explanation: The rule of five applies to self-designed containers that
rely at least partly on manual memory management for the data of which they have
ownership. It states that for such classes, the programmer should implement each
of the following, or else they will be restricted in their functionality:
- The destructor; strictly needed, without it there can be a memory leak.
- The copy constructor; if it is not there, copying during initialization of another object will not work correctly.
- The copy assignment operator; without it, copying to a pre-existing (already constructed) object will not work correctly.
- The move constructor; implementing it can speed up storing content in a new object right before an old one is deallocated.
- The move assignment operator; it can speed up moving content from an object that is about to be deallocated into a pre-existing (already constructed) object.
See also: Allocation, deallocation.
Scope
Definition: The scope of a name (e.g., for the name of a variable or function) is the region within the source code to which the declaration of that name applies.
- Within its scope, a name can be resolved, i.e., understood by the compiler as referring to something (a variable, a function, a class, etc.). Outside of its scope it cannot be resolved - it appears to the compiler as something unknown.
See also: Global variable, namespace.
Strong scaling
See also: Concurrency
void
Summary (not a definition): "void" is a keyword from the C/C++ programming language; it is not a data type, but can be used where C/C++ syntax would otherwise require a data type, e.g., in the position of the return type for a function that does not have a return value.
- The keyword "void" is just an element of the C/C++ language and its syntax. There is no useful programming concept behind it that would merit a definition.
See also: Function, pointer, return value.
Index