1-C__Primer

1-C__Primer - C+ History C+ CPL Combined Programming...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ History C++ History CPL – Combined Programming Language (1960s, University of Cambridge, University of London) BCPL – Basic Combined Programming Language (1966, Martin Richards, language for writing compilers) GET "libhdr" LET start() = VALOF { FOR i = 1 TO 5 DO writef("fact(%n) = %i4*n", i, fact(i)) RESULTIS 0 }AND fact(n) = n=0 -> 1, n*fact(n-1) B (Dennis Ritchie, Bell Labs, 1969) printn(n,b) { extrn putchar; auto a; if(a=n/b) /* assignment, not test for equality */ printn(a, b); /* recursive */ putchar(n%b + '0'); } •C (Dennis Ritchie, Bell Labs, early 1970s, general purpose) C++ (Stroustrup, Bell Labs, 1983, C with objects) •C++/CLI (Microsoft, 2005, “Managed” ECMA C++ Standard)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
How C++ Works How C++ Works Source Code Preprocessed Source Code Object Code Executable Code Preprocessor Compiler Linker Native MSIL Interpreter CPU OS
Background image of page 2
C++ Preprocessor C++ Preprocessor 1. Source files processed by preprocessor to shape the code by substituting attributes*, expanding macros, processing conditional directives, including external files, issuing compiler directives 2. Preprocessor directives begin with # 3. Attributes (COM, IDL, compiler, .NET) are enclosed in [], e.g. [in] * Attributes are Microsoft’s innovation, that just now has been standardized by ECMA
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Preprocessor Definitions Preprocessor Definitions #define can define a flow control entity*: #define MYHEADER_H * Capitalize the name, use underscore to separate words a constant*: #define MYHEADER_H #define M_PI 3.1415f * Capitalize the name, use underscore to separate words or a macro*: #define MAX(a, b) ((a) > (b) ? (a) : (b)) * Capitalize the name, enclose operands in parenthesis #undef undefines a previously defined entity: #undef M_PI #undef MAX #undef MYHEADER_H
Background image of page 4
Including Files Including Files #include #include "MyHeader.h" #include <iostream> * Name your include files .h What’s appropriate for include files? * Declarations, e.g. constants, external functions, classes, structures, macros, etc. What’s inappropriate for include files? * Code snippets, function bodies, class implementations, i.e. non-declarative code
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Conditional Compilation Conditional Compilation #if / #ifdef / #ifndef - #else / #elif - #endif #ifndef MYHEADER_H #include "MyHeader.h" #elif MYHEADER_VERSION < 2 #error MyHeader.h version 2 is required #else // Everything is OK #endif Another example #ifdef DEBUG TRACE("Running in DEBUG mode"); #endif #ifdef NAME is equivalent to #if defined(NAME)
Background image of page 6
Including Files Properly Including Files Properly In the header… #ifndef MYHEADER_H #define MYHEADER_H // Header declarations go here // … #endif Alternatively in the header… #pragma once // Header declarations go here In the code… #include <MyHeader.h>
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Preprocessor Advice Preprocessor Advice Use preprocessor to define literal constants, macros Conditional compilation with minimum effect is OK (e.g. debug vs. non-debug code) DO NOT use preprocessor to alter the program logic excessively, especially do not apply conditional compilation directives to large chunks of code
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 31

1-C__Primer - C+ History C+ CPL Combined Programming...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online