Week 1 Flashcards
(29 cards)
Objects are instances of _______
classes
Object-oriented languages offer three high-level features for programming solutions:
encapsulation
inheritance
polymorphism
fundamental types:
correspond directly to the. hardware facilities
built-in types:
reflect the capabilities of the hardware facilities directly and efficiently
User-defined types
concrete types:
abstract types:
concrete types - their representation is part of their definition and is known
abstract types - their representation is not part of their definition and is unknown
declaration:
A declaration introduces a name into a program and associates that name with a type.
ex.
int x;
void display();
4 types of scopes:
local scope - the name has been declared within a function or code block
class scope - the name has been declared as a member of a class
namespace scope - the name has been declared as a member of a named block
global scope - the name has not been declared in any one of the above scopes
linkage:
A name has a linkage if it can refer to an identical name declared in another scope. Linkage is optional.
The linkage of a name may be
external - connected across different scopes in different modules
internal - connected across different scopes within the same module
non-existent - not connected to any entity outside its own scope
memory distinctions:
code segment - stores the program instructions
data segments - store data that survives the lifetime of the program
stack segment - stores local data that is, statically allocated
heap segment - stores local data that is dynamically allocated
definition:
A definition is a declaration that associates a meaning with a name. A declaration may be a definition but is not necessarily a definition.
one-definition rule:
A definition may not appear more than once across all translation units. No translation unit may contain more than one definition of a variable, function, class or template. If a definition appears in multiple translation units, that definition must be identical in all translation units in which it appears.
scope:
The scope is the region of the program throughout which the name is valid; that is, the region where the entity identified by that name is visible.
initializer expressions:
The scope of a name declared in the selection condition of a selection construct extends to the end of the construct itself.
ex.
if (int j = i % 10; j < 5) {
i -= j;
access a shadowed global variable with the name ‘x’:
use the scope resolution operator:
::x
external linkage:
A name with external linkage refers to an entity that is declared in a different scope within another translation unit. The C++ keyword extern identifies external linkage.
ex.
extern int share_me; // declaration
We omit this linkage keyword in the translation unit that defines and initialize the named entity:
int share_me = 0; // definition
C++ ignores the extern keyword if an initialization is present.
internal linkage:
A name with internal linkage refers to an entity that is invisible outside its own translation unit, but visible to other scopes within its translation unit. The C++ keyword static identifies internal linkage.
ex.
static int local = 2;
what is a volatile type?
A value stored in a volatile type is subject to side-effects and needs its memory location updated every single time that the CPU changes that value.
what is a type definition?
A type definition is an alias for a type. A type definition can simplify code readability for compound types.
The C++ keyword typedef identifies a synonym for a specified type. A type definition takes the form
typedef compoundType Synonym;
namespaces:
A namespace is a scope that limits the visibility of its names with respect to the program as a whole.
using declaration:
To minimize repetition of scope resolution, we can expose a name within a namespace by a using declaration. A using declaration takes the form
using namespace::identifier;
anonymous namespaces:
Anonymous namespaces provide a means of isolating names within a translation unit. The names declared within an anonymous namespace are only visible inside their own translation unit and invisible to all other translation units. If a definition appears in multiple translation units, it can differ across the translation units if it is within anonymous namespaces in each translation unit.
ex. namespace { // code here }
good design practice - using declarations:
using declarations and directives complicate header file inclusions.
Since we cannot determine the order in which header files will be included within another source file, we qualify all names within the header file with their namespace’s identifiers and the scope resolution operator. It is good design practice to avoid the using directive or declaration in any header file.
The storage duration of a variable or object defines its lifetime within a program. Storage duration may be one of the following:
automatic - lasts from its declaration to the end of its scope - no keyword
static - lasts the entire lifetime of the program - use keyword static
dynamic - created using the keyword new - last until deallocated using the keyword delete
thread - lasts the lifetime of the thread - use keyword thread_local
Three stages of the compilation process:
Pre-Processing Stage - the pre-processor creates a separate translation unit from the original source files for each module by inserting the header files into the implementation file and replacing or expanding any macros (lines starting with #)
Compilation Stage - the compiler creates a separate binary file from each translation unit
Linking Stage - the linker creates a single relocatable file from the binary files for all translation units and the binary files for any referenced libraries.