100 likes | 320 Vues
C. C ?. K & R C -- 1972 The Kernighan and Richie classic ANCI C -- started 1983 ANSI X3.159-1989 and ISO/IEC 9899:1990 Standard C, C89, C90 C90 Another ANSI standard (adds C++ features) GCC. C with objects. C++ Used for business and gaming applications Java
E N D
C ? • K & R C -- 1972 • The Kernighan and Richie classic • ANCI C -- started 1983 • ANSI X3.159-1989 and ISO/IEC 9899:1990 • Standard C, C89, C90 • C90 • Another ANSI standard (adds C++ features) • GCC
C with objects • C++ • Used for business and gaming applications • Java • Used for networking and user interface • Executes on a “virtual machine” • C# • Used by Microsoft
Why C? • Programs can be fast • Programs can be small • Runs on many platforms • Including embedded processors • Generally with some version of GCC • Relatively easy to learn • Useful “standard” library
Why not C? • Can get very obscure • ++a = *p->q + b * (x>y ? 5 : 13) ; • Can lack robustness • Many viruses “attack” servers written in C • Hard to manage large software projects • Without object-oriented techniques • C++ can be fast • Java can be small
C program -- 1 of 2 #include <stdio.h> void countdown(int n) { int i ; for (i=n; i>= 1; --i) printf("%4d\n", i) ; puts("*** blastoff ***") ; }
C program -- 2 of 2 int main(int argc, char *argv[]) { int count ; puts("Enter start of count!") ; scanf("%d", &count) ; countdown(count) ; return 0 ; }
Running NCSU ECE 209 style $ nano example.c $ ls -l example* -rw-r--r-- 1 brock 501 278 Aug 17 17:48 example.c $ gcc -ansi -pedantic -Wall -Werror -o example example.c $ ls -l example* -rwxr-xr-x 1 brock 501 14796 Aug 17 17:48 example -rw-r--r-- 1 brock 501 278 Aug 17 17:48 example.c $ ./example
Looking at object code $ nano example.c $ gcc -ansi -pedantic -Wall -Werror -c example.c $ ls -l example* -rw-r--r-- 1 brock 501 278 Aug 17 17:48 example.c -rw-r--r-- 1 brock 501 936 Aug 17 17:58 example.o $ gcc -o example example.c
Looking at assembly code $ gcc -ansi -pedantic -Wall -Werror -S example.c From example.s i=n movl 8(%ebp), %eax movl %eax, -12(%ebp) --i followed by i>=1 leal -12(%ebp), %eax subl $1, (%eax) L2: cmpl $0, -12(%ebp) jg L3