cs 240 programming in c
play

CS 240 Programming in C Introduction September 4, 2019 Haoyu Wang - PowerPoint PPT Presentation

CS 240 Programming in C Introduction September 4, 2019 Haoyu Wang UMass Boston CS 240 September 4, 2019 1 / 24 Schedule Course Introduction 1 Programming Overview 2 History of C Language 3 Editor 4 Intro of Linux Command-line 5


  1. CS 240 Programming in C Introduction September 4, 2019 Haoyu Wang UMass Boston CS 240 September 4, 2019 1 / 24

  2. Schedule Course Introduction 1 Programming Overview 2 History of C Language 3 Editor 4 Intro of Linux Command-line 5 Haoyu Wang UMass Boston CS 240 September 4, 2019 2 / 24

  3. Course Introduction The course lecture materials I am using are mostly based on the professor Ming Ouyang’s past CS240 course materials. I am much grateful for his gracious help and guidance. However, I made some changes based on my preferences. Haoyu Wang UMass Boston CS 240 September 4, 2019 3 / 24

  4. Course Evaluation The final grade is determined by 40% of homework and 60% of tests. There will be three in class paper tests. For how many homework, we will see how class progress during semester. We will see if I will drop the lowest homework grade for all based how class progress. If you understood course topics and done the homework well, you will get good grades. Haoyu Wang UMass Boston CS 240 September 4, 2019 4 / 24

  5. Discussion Announcements and discussions will be posted on Blackboard Check Blackboard and read your email regularly Haoyu Wang UMass Boston CS 240 September 4, 2019 5 / 24

  6. Plagiarism Don’t do it in any form or it will be reported. Test cheating will lead to fail. Haoyu Wang UMass Boston CS 240 September 4, 2019 6 / 24

  7. Development environment setup Done? Haoyu Wang UMass Boston CS 240 September 4, 2019 7 / 24

  8. Linux Server Access Linux server. Transfer files between your machine and sever. Haoyu Wang UMass Boston CS 240 September 4, 2019 8 / 24

  9. Submission of Homework For the submission of homework, I will note it in each homework. Haoyu Wang UMass Boston CS 240 September 4, 2019 9 / 24

  10. Textbook The C Programming Language, 2nd Edition, 1988, by Brian Kernighan and Dennis Ritchie The ”K&R” is often being referenced to either this book or these two computer scientists, cause they two are just that important and great. ”K&R” created the C language in order to write UNIX system efficiently. You could just search the bio of them to learn a lot about the early history of programming language. Haoyu Wang UMass Boston CS 240 September 4, 2019 10 / 24

  11. Reading Suggestions Read the textbook ahead of the class, but don’t expect to understand everything. Skip preface. Skip or skim through introduction. You will understand better introduction after you are familiar with lots of the concepts of C. Haoyu Wang UMass Boston CS 240 September 4, 2019 11 / 24

  12. Programming Overview Now, let’s getting into some basic computer principle. CPU executes on lines of binary digits or bits, called machine language or machine code or object code. Machine language is the only language a computer is capable of understanding. To see a binary code, you could type in linux terminal xxd file-name for hexadecimal encoding or xxd -b file-name for binary encoding. If you open a compiled C or Java program in a text editor like sublime text, you will see the lines of hexadecimal bits, not English characters, because a binary file contains the information about its way of encoding. Haoyu Wang UMass Boston CS 240 September 4, 2019 12 / 24

  13. Programming Overview How a line of binary digits is executed is determined by a CPU’s instruction set architecture (ISA) which is also referred to as architecture or computer architecture. Let’s take an ’example’ for a figurative sense of understanding. 00000001 00000002 00000003 Let’s set 00000001 means addition for a ’dummy’ CPU 00000002 and 00000003 means address. Then this ’dummy’ CPU executes this line of binary digits, it adds the data in addresses of 00000002 and 00000003 means. Again this example is for a intuitive understanding of how CPU runs binary codes, it is by no means right in any sense. Haoyu Wang UMass Boston CS 240 September 4, 2019 13 / 24

  14. Binary code Take a look at Punched Tape Codes in early days, which means binary code on tape. http://www.chilton-computing.org.uk/ acl/literature/chapman/p015.htm However, it is impractical for programmers to write programs directly in binary digits. In reality, programmers write program in English character with certain rules tied to ISA, which are stipulated by different compilers, i.e. different programming languages, like C, Java, etc.. And the text code written by programmers is called source code. So as a programmer, you will work on writing source code and then compile it for executing. Haoyu Wang UMass Boston CS 240 September 4, 2019 14 / 24

  15. Compiler The main processes of a modern compiler are working like these: source code → preprocessor → complier → assembler → object code → linker → executables In reality, the whole processes are divided into source code writing and compiling. Let’s take two examples of ”Hello world!” in C and Java to see what this means. Haoyu Wang UMass Boston CS 240 September 4, 2019 15 / 24

  16. Compiler gcc -o hello hello.c ./hello javac hello.java java hello ’.’ means current folder; ’./hello’ means executing binary file hello in current folder directly on OS. ’java hello’ means executing Java binary file in current folder within Java Virtual machine. Haoyu Wang UMass Boston CS 240 September 4, 2019 16 / 24

  17. Script Language Some language called script language, like bash, python, integrates compiling and executing processes together so that source code can be directly executed. For example, python hello.py Haoyu Wang UMass Boston CS 240 September 4, 2019 17 / 24

  18. C Language History Let’s talk about a little bit of the history of C. The C programming language was devised in the early 1970s by Dennis M. Ritchie an employee from Bell Labs (ATT). It was actually created to move the UNIX kernel code from assembly to a higher level language, which would do the same tasks with fewer lines of code. The UNIX operating system which started in 1969,then was rewritten in C in 1972. Since it’s birth, C is closely related to operating system. Haoyu Wang UMass Boston CS 240 September 4, 2019 18 / 24

  19. C Language and OS Linux is directive derivative of Unix, which is written mostly in C, with some parts in assembly. Linux was intended for personal computers based on the Intel x86 architecture and free of using. Now about 97 percent of the worlds 500 most powerful supercomputers run the Linux kernel. Microsofts Windows kernel and Mac OS X kernel are also developed mostly in C, with some parts in assembly language. Every program and driver in a Mac, as in Windows and Linux computers, is running on a C-powered kernel. Besides the worlds most popular databases, including Oracle Database, MySQL, MS SQL Server, and PostgreSQL, are coded in C and C++. Haoyu Wang UMass Boston CS 240 September 4, 2019 19 / 24

  20. Speed of C program Since C programs can be run directly on OS system, they are as fast as programs can be. A speed comparison. https://leetcode.com/problems/two-sum/submissions/ For all implementations of the same algorithm in different languages, the C implementation is the fastest. It is mostly because other languages have to run in a Virtual Machine resides on operating system other than on os itself. Haoyu Wang UMass Boston CS 240 September 4, 2019 20 / 24

  21. Editors on Linux vi Installed by default on typical Linux installations Popular among system admins vim is a variant A tutorial https://www.tutorialspoint.com/unix/unix-vi-editor.htm emacs Installed by this command: sudo yum install emacs A lot bigger and a little slower than vi A guided tour http://www.gnu.org/software/emacs/tour/ On our department server, there is also a simpler editor Nano. Vi/vim and emacs are professional and come well along with linux system. However they are time consuming to learn and frustrating to use for beginners. Haoyu Wang UMass Boston CS 240 September 4, 2019 21 / 24

  22. Editor Demo Let’s do a simple tutorial. Nano: this is simple. vim: https://cdn.infographicwebsite.com/wp-content/uploads/ 2019/05/vim-cheat-sheet.png Haoyu Wang UMass Boston CS 240 September 4, 2019 22 / 24

  23. Basic commands Let’s do a simple tutorial. https://www.git-tower.com/blog/command-line-cheat-sheet Haoyu Wang UMass Boston CS 240 September 4, 2019 23 / 24

  24. End Begin to read the first chapter, and try the examples on your home machine or server! Haoyu Wang UMass Boston CS 240 September 4, 2019 24 / 24

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend