Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C?...

download Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.

If you can't read please download the document

description

Department of Electronic & Electrical Engineering Why not C? With power comes responsibility. More typing then other higher level languages Some programming errors can lead to code that is very hard to debug. Languages like java do a lot more checking Possible to write very cryptic code in C! Libraries not standardised Windows Linux e.g. networking libraries

Transcript of Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C?...

Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple program HelloWorld.c Running/debugging. Department of Electronic & Electrical Engineering Why C ? Fast / Flexible / Access to hardware. Good for embedded applications. Unix + Other OS written in C C programs run on many types of processor Good selection of libraries Possible to write well structure code. Industry standard. Department of Electronic & Electrical Engineering Why not C? With power comes responsibility. More typing then other higher level languages Some programming errors can lead to code that is very hard to debug. Languages like java do a lot more checking Possible to write very cryptic code in C! Libraries not standardised Windows Linux e.g. networking libraries Department of Electronic & Electrical Engineering "Hello World" Summary #include int main() { printf("Hello World \n"); return 1; } Pre-processor directive IO library Function declaration Block statement (body of function) Function (part of stdio) Function call statement Character string constant First argument passed to printf Return statement Returns the value 1 Special character Carriage return Semi colon Terminates statements Department of Electronic & Electrical Engineering python for comparison print "Hello World" Department of Electronic & Electrical Engineering Development Cycle 1.Write code HelloWorld.c 2.Compile code (compiler) HelloWorld.obj 3.Fix compile time errors (syntax) goto 2. 4.Link your code with libraries (linker) HelloWorld.exe 5.Fix linking errors (missing functions e.g. printff) 6.Run code 7.Fix run time errors (your mistakes) goto back to 1. 8.Program works !!! machine code Department of Electronic & Electrical Engineering Development Environment (linux command line). Create your source code using the editor of your dreams... $ gedit prog.c Compile into machine code using gcc (compiler more) prog.o $ gcc prog.c c Link with all the libraries using gcc (linker mode) a.out $ gcc prog.o OR in one step $ gcc prog.c