1
Evolution of Programming Languages
• 40's machine level
– raw binary
• 50's assembly language
– names for instructions and addresses
– very specific to each machine
• 60's high-level languages
– Fortran, Cobol, Algol
• 70's system programming languages
– C
– Pascal (more for teaching structured programming)
• 80's object-oriented languages
– C++, Ada, Smalltalk, Modula-3, Eiffel, …
strongly typed languages
better control of structure of really large programs
better internal checks, organization, safety
• 90's "scripting", Web, component-based, …
– Java, Visual Basic, Perl, …
strongly-hyped languages
focus on interfaces, components
Why C++ first? Why not Java?
• historical sequence
– C++ tries to remedy drawbacks and limitations of C
– Java reacts to size and complexity of C++
• compatibility with C
– source and object
• mechanisms are visible and controllable, e.g.,
– classes have zero overhead in simplest cases
– classes are not mandatory
– garbage collection is not automatic but can be
programmed
– can use C I/O or define a new one
• C++ is a significantly more powerful language
– but is significantly bigger and more complicated
• personal taste and experience
2
Stacks in C: a single stack
int stack[100];
int *sp = stack; /* first unused */
#define push(n) (*sp++ = (n))
#define pop() (*--sp)
for (i = 0; i < 10; i++)
push(i);
Stacks in C: a stack type
typedef struct {
int stk[100];
int *sp;
} stack;
int push(stack s, int n) {
return *s.sp++ = n;
}
int pop(stack s) {
return *--s.sp;
}
stack s1, s2;
for (i = 0; i < 10; i++)
push(s1, i);
3
Another stack implementation
typedef struct {
int *stk;
int *sp;
} stack;
int push(stack *s, int n) {
return *s->sp++ = n;
}
int pop(stack *s) {
return *--s->sp;
}
stack *s1, *s2;
not initialized
s1->stk =
(int *) malloc(100 * sizeof(int));
ugly
for (i = 0; i < 10; i++)
push(*s1, i);
Problems
• representation is visible, can't be protected
(e.g., s1->stk)
• creation and copying must be done very carefully
– and you don't get any help with them
• no initial