Page 1. Agenda. Programming Languages. C Compilation Process

Similar documents
CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

C Introduction. Comparison w/ Java, Memory Model, and Pointers

Topic 6: A Quick Intro To C

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Lectures 5-6: Introduction to C

C - Basics, Bitwise Operator. Zhaoguo Wang

Final CSE 131B Spring 2004

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

ELEC 377 C Programming Tutorial. ELEC Operating Systems

Modifiers. int foo(int x) { static int y=0; /* value of y is saved */ y = x + y + 7; /* across invocations of foo */ return y; }

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

C: Program Structure. Department of Computer Science College of Engineering Boise State University. September 11, /13

PRINCIPLES OF OPERATING SYSTEMS

CS 61C: Great Ideas in Computer Architecture Introduction to C

TDDB68 Concurrent Programming and Operating Systems. Lecture 2: Introduction to C programming

Lectures 5-6: Introduction to C

Introduction to the C Programming Language

Programming refresher and intro to C programming

C Tutorial: Part 1. Dr. Charalampos C. Tsimenidis. Newcastle University School of Electrical and Electronic Engineering.

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

Exercise Session 2 Systems Programming and Computer Architecture

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Compiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009

G52CPP C++ Programming Lecture 6. Dr Jason Atkin

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu

Online Judge and C. Roy Chan. January 12, Outline Information Online Judge Introduction to C. CSC2100B Data Structures Tutorial 1

EL6483: Brief Overview of C Programming Language

Lecture 03 Bits, Bytes and Data Types

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012

CMPT 115. C tutorial for students who took 111 in Java. University of Saskatchewan. Mark G. Eramian, Ian McQuillan CMPT 115 1/32

QUIZ. What are 3 differences between C and C++ const variables?

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

EL2310 Scientific Programming

Object-Oriented Programming

COSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14

#include <stdio.h> int main() { printf ("hello class\n"); return 0; }

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

Data Structures Unit 02

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( )

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

TDDE18 & 726G77. Functions

Computers Programming Course 5. Iulian Năstac

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science

EL2310 Scientific Programming

Kurt Schmidt. October 30, 2018

Chapter 11 Introduction to Programming in C

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

C Programming Review CSC 4320/6320

Chapter 11 Introduction to Programming in C

Short Notes of CS201

Computational Expression

Introduction to Java

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

CS201 - Introduction to Programming Glossary By

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C

CSE 333 Lecture 2 Memory

6.096 Introduction to C++ January (IAP) 2009

Programming in C - Part 2

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

13 th Windsor Regional Secondary School Computer Programming Competition

Numerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2

Motivation was to facilitate development of systems software, especially OS development.

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

COMP26120: Algorithms and Imperative Programming. Lecture 5: Program structuring, Java vs. C, and common mistakes

Structures, Unions Alignment, Padding, Bit Fields Access, Initialization Compound Literals Opaque Structures Summary. Structures

CS3157: Advanced Programming. Outline

/* defines are mostly used to declare constants */ #define MAX_ITER 10 // max number of iterations

A Fast Review of C Essentials Part I

CMPE-013/L. Introduction to C Programming

a data type is Types

An Ungentle Introduction to C

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Lab 1: First Steps in C++ - Eclipse

Chapter 11 Introduction to Programming in C

Lecture 2. Xiaoguang Wang. January 16th, 2014 STAT 598W. (STAT 598W) Lecture 2 1 / 41

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

EMBEDDED SYSTEMS PROGRAMMING Language Basics

Motivation was to facilitate development of systems software, especially OS development.

Chapter 11 Introduction to Programming in C

IBM Rational Rhapsody TestConductor Add On. Code Coverage Limitations

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion

JTSK Programming in C II C-Lab II. Lecture 3 & 4

EC 413 Computer Organization

Chapter 2. Procedural Programming

EL2310 Scientific Programming

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

Biostatistics 615/815 - Lecture 2 Introduction to C++ Programming

Have examined process Creating program Have developed program Written in C Source code

COMP322 - Introduction to C++

CS240: Programming in C. Lecture 2: Overview

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers

Transcription:

EE 472 Embedded Systems Dr. Shwetak Patel Assistant Professor Computer Science & Engineering Electrical Engineering Agenda Announcements C programming intro + pointers Shwetak N. Patel - EE 472 2 Programming Languages C Compilation Process Source -> Preprocessor -> Compiler -> Assembler -> Linker -> Loader Shwetak N. Patel - EE 472 3 Shwetak N. Patel - EE 472 4 Page 1

Example Program in C Loops #include <stdio.h> // this imports a definition file (a header). int main() // note the return type of main: 0 means ok { int x=5; printf("local = %d", x); return 0; // return success for(int i = 0; i < 100; i++){ int i = 0; while(i < 100){ i++; Shwetak N. Patel - EE 472 5 Shwetak N. Patel - EE 472 6 Functions int processdata(int X){ return (X*X)/2; Shwetak N. Patel - EE 472 7 C types char short java 16 bits c 8 bits 16 bits 16 bits int 16,32 or 64 32 bits bits long 64 bits 32 or 64 bits float 32 bits 32 bits double 64 bits 64 bits boolean 1 bit 1 bit or int byte 8 bits use char long long N/A 64 bits long double N/A 80,96 or 128 bits Shwetak N. Patel - EE 472 8 Page 2

Unsigned types Boolean Operators with Integer types int i1; // range -2,147,483,648 to 2,147,483,647 signed int i2; // range -2,147,483,648 to 2,147,483,647 unsigned int i2; // range 0 to 4,294,967,295 967 295 singed: -2 n-1 to 2 n-1-1 unsigned: 0 to 2 n-1-1 1 && 1 == 1 1 && 0 == 0 1&&-3 ==1 7 25 == 1!34 == 0 Shwetak N. Patel - EE 472 9 Shwetak N. Patel - EE 472 10 Visibility and Lifetime Global vs Local int counter; main () { int foo = 2; // not visible outside of this function int glob = 2; // not visible outside of this function for (int i=3;...) { int global; // outside function void somefunction(void) { int local; // within function Shwetak N. Patel - EE 472 11 Shwetak N. Patel - EE 472 12 Page 3

Extern and Static Constants /* fileone.c: */ const float PI = 3.14; //have to declare and initialize int global = 2; // defines a global integer variable static int private = 5; // all functions in fileone can use // Not visible outside of file /* filetwo.c: */ extern int global; // declares that filetwo.c wants to use the // variable defined in fileone.c static int private = 7; // A new variable only visible within filetwo.c int main(){ float r = 10.0; float area = PI * r * r; void function(void) { int local = global * private; // local variable == 2*7 Shwetak N. Patel - EE 472 13 Shwetak N. Patel - EE 472 14 #define #define vs const #define PI 3.14 int main(){ float r = 10.0; float area = PI * r * r; #define handled by preprocessor Straight text replacement (think search & replace) #const handled by compiler Type checking Shwetak N. Patel - EE 472 15 Shwetak N. Patel - EE 472 16 Page 4

Other preprocessor directive Why use preprocessor #ifdef #endif #define LINUX 1 //#define WINDOWS 1... Debugging Multi platform code Others? #ifdef WINDOWS... windows -specific code... #endif #ifdef LINUX... linux -specific code... #endif Shwetak N. Patel - EE 472 17 Shwetak N. Patel - EE 472 18 Class Exercise Class Exercise Shwetak N. Patel - EE 472 19 Shwetak N. Patel - EE 472 20 Page 5

typedef typedef defines a custom type (synonym) Usage: typedef type synonym ex: typedef unsigned int myint; myint x = 100; type conversion char c = b ; int i = (int) c; unsigned short x = 100; int i2 = (int) x; Shwetak N. Patel - EE 472 21 Shwetak N. Patel - EE 472 22 Pointers and Memory Memory Warning: Sleepy eye syndrome Shwetak N. Patel - EE 472 23 Shwetak N. Patel - EE 472 24 Page 6

Getting the address of a variable Pointers &mydata0; //read address of mydata0 Where do we put the address? Pointer - just a variable that holds a memory address int* mydata0ptr = &mydata0; 1) mydata0ptr variable name 2) is a pointer - * specifies that 3) to an integer int specfies that 4) mydata0ptr is an pointer to an integer Shwetak N. Patel - EE 472 25 Shwetak N. Patel - EE 472 26 dereferencing How do we get the value of what the pointer points to? int mydata1 = *mydata0ptr Shwetak N. Patel - EE 472 27 Shwetak N. Patel - EE 472 28 Page 7

Class Exercise Shwetak N. Patel - EE 472 29 Shwetak N. Patel - EE 472 30 C Development Options C Development Options Note: This is for building apps for your PC to practice your C programming Mac OSX: Xcode (gcc compiler) Free download includes IDE (integrated development environment) Windows: Option 1: Visual Studio (includes C compiler and IDE) Option 2: Install Cygwin and use gcc from command line Option 3: Install Cygwin and use Eclipse Others: Netbeans, etc Linux: gcc included Use any IDE (eclipse, emacs, etc) Shwetak N. Patel - EE 472 31 Shwetak N. Patel - EE 472 32 Page 8

Eclipse and C in Windows Questions? Install Cygwin Make sure to install the gcc-core: C compiler and make: The GNU version packages under devl Set your path in windows to c:\cygwin\bin Install Eclipse UDE for C/C++ Developers Next time: Tutorial on make platform More C practice Structures and Representing Data Bitwise Operations Create new sample C application Shwetak N. Patel - EE 472 33 Shwetak N. Patel - EE 472 34 Page 9