EECS 388 C Introduction. Gary J. Minden August 29, 2016

Similar documents
Presented By : Gaurav Juneja

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Programming in C++ 4. The lexical basis of C++

INTRODUCTION 1 AND REVIEW

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

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

VARIABLES AND CONSTANTS

C Language, Token, Keywords, Constant, variable

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Tokens, Expressions and Control Structures

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

Data Types and Variables in C language

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science

Basic Types, Variables, Literals, Constants

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Basic Elements of C. Staff Incharge: S.Sasirekha

C: How to Program. Week /Mar/05

Chapter 2 - Introduction to C Programming

A Fast Review of C Essentials Part I

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

Preview from Notesale.co.uk Page 6 of 52

Procedures, Parameters, Values and Variables. Steven R. Bagley

>B<82. 2Soft ware. C Language manual. Copyright COSMIC Software 1999, 2001 All rights reserved.

Introduction to C Language

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

DEPARTMENT OF MATHS, MJ COLLEGE

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

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

BLM2031 Structured Programming. Zeyneb KURT

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

Chapter 1 Introduction to Computers and C++ Programming

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Programming in C and C++

Java Notes. 10th ICSE. Saravanan Ganesh

6.096 Introduction to C++ January (IAP) 2009

Introduction to C# Applications

Syntax and Variables

Chapter 1 & 2 Introduction to C Language

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

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

Programming. C++ Basics

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Lecture 2 Tao Wang 1

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

XSEDE Scholars Program Introduction to C Programming. John Lockman III June 7 th, 2012

Variables and literals

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Types, Operators and Expressions

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Types, Variables, and Constants

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

Review of the C Programming Language for Principles of Operating Systems

Programming in C and C++

Fundamental of Programming (C)

Types, Operators and Expressions

Programming and Data Structures

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

Differentiate Between Keywords and Identifiers

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

CHAPTER-6 GETTING STARTED WITH C++

CSC 1107: Structured Programming

Chapter 2. Lexical Elements & Operators

Short Notes of CS201

C Programming Language Training. This instruction relies on the C language described in C++: The Complete Reference Third Edition By Herbert Schildt

BASIC ELEMENTS OF A COMPUTER PROGRAM

CS201 - Introduction to Programming Glossary By

Chapter 2: Overview of C. Problem Solving & Program Design in C

Introduction to the C Programming Language

1 Lexical Considerations

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

PROGRAMMAZIONE I A.A. 2018/2019

Creating a C++ Program

Special Topics for Embedded Programming

Fundamentals of Programming

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Computer System and programming in C

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc Introduction to Computing

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

We do not teach programming

EL2310 Scientific Programming

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

1/29/2018. Starting a Program Executes its main Function. ECE 220: Computer Systems & Programming. The Function main Divides into Two Parts

CHW 469 : Embedded Systems

Lexical Considerations

A S H O R T I S H O V E R V I E W O F T H E A N S I C P R O G R A M M I N G L A N G U A G E

CSCI 171 Chapter Outlines

Computational Physics Operating systems

XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.

1.1 Introduction to C Language. Department of CSE

Computers Programming Course 5. Iulian Năstac

Data Structures Unit 02

2 rd class Department of Programming. OOP with Java Programming

Review of the C Programming Language

Transcription:

EECS 388 C Introduction Gary J. Minden August 29, 2016 1

C Developed at AT&T Bell Laboratories in the early 1970s by Dennis Richie Intended as a systems programming language, that is used to write operating systems and embedded kernels Efficient, code is fast and compact Intended to be somewhat portable, but that is not always the case Popularized through the UNIX and Berkeley UNIX (BSD) operating systems initially and today through Linux C programming systems come with an almost standard set of library subroutines (libc.a) 2

C References There are many books on C S. P. Harbison and G. L Steele, Jr., C: A Reference Manual, 3 ed., Prentice Hall, Englewood Cliffs, NJ, 1991, ISBN: 0-13-110933-2. Other References The International Standard for C D. Richie s C Reference Manual The GNU libc reference C Style Guides Available at: http://www.ittc.ku.edu/~gminden/embedded_systems/content/ Datasheets.html 3

C Identifiers Identifiers name programming entities Variables, constants, subroutines, data types, and data structures Identifiers must start with an underscore _ or a letter [a...z] or [A...Z] After the initial underscore or letter, identifiers can contain underscores, letters, or digits Identifiers are case sensitivity abc is distinct from Abc ANSI (American National Standards Institute) requires at least 31 leading characters to be significant Many implementations support more significant characters Longer identifiers tend to increase program clarity and mixing upper and lower case and use of underscores leads to more readable identifiers. 4

C Identifier Examples Examples of C Identifiers are: Task_1_Init SysTickCount Task_2_State Identifiers are automatically created in the compiler symbol table when you define variables, constants, subroutines, data types, and data structures There may be additional restrictions or allowances on identifiers when interfacing to system software E.g. Identifier significant length or additional characters, respectively 5

C Primary Data Types C enables defining new data types in terms of existing data types For most of our work, we will use pre-defined data types. The common data types we will use are: int short char int32_t int16_t int8_t bool uint32_t uint16_t uint8_t int32_t represents a 32-bit number If treated as a two s complement number, values are between 2^-31 and 2^31-1 If treated as a unsigned number, values are between 0 and 2^32-1 char represents a 8-bit, integer value Also used for single characters The ARM processors we use does not support the floating point type float 6

C Primary Data Types enum is a set of values enum States { On, Off, TriState } GateState; Usually treated as int32_t struct is a collection of typed values struct S { int Red; int Green; int Blue } Color; Color.Red; typedef -- a new type is being defined typedef struct S { int Red; int Green; int Blue } S; struct S Color1, Color2; union -- multiple views of the same set of bits union U { int A; char Word[4]; } Foo; Foo.A; Foo.Word[0] 7

Type Qualifiers (Old way) unsigned To declare a variable unsigned, use the unsigned modifier unsigned int A, B, C; long To declare a variable as long (generally 32-bits), use the long modifier This is not needed in our programs, integers are 32-bits by default You will see it in some example code because it is good practice to be explicit short To declare a 16-bit integer, use the short modifier unsigned short int A, B, C; volatile Values are altered outside the control of the program volatile uint32_t SysTickCount = 0; 8

Numbers, Characters, and Strings Constant integers can be represented in decimal radix or hexadecimal radix Decimal radix is just a sequence of digits, e.g. 5463 Hexadecimal radix is preceded by 0x and followed by the digits 0...9 and letters a...f (or A...F), e.g. 0xFF03 would be a 16-bit integer Characters (char) are 8-bit integers Character constants are enclosed in single quotes, e.g. A, 4, and \n The backslash enables representing control characters: \n represents a newline character (named Linefeed in ASCII), \0 represents the Null (value 0) character which terminates strings. A sequence (array) of charterers is a string String constants are defined with double-quotes, e.g. TickCount: %d Strings are terminated by a Null character, \0 or 0x00 9

Arrays int32_t, int16_t, and char can be organized into a sequence or vector of values Example syntax is: int32_t DataInput[ k ]; char InputString[ 256 ]; Multi-dimensional arrays can be allocated int32_t Image[ 16 ] [16 ]; represents a 16x16 image of 32-bit integers The first element in an array has index 0. The last element has index <size-of-array>-1 10

Initializing Variables Variables can be initialized at compile time. The syntax is: declaration = expression; Where declaration is a variable definition and expression evaluates to a value. Examples are: int32_t A = 54; char thechar = A ; Initial array values are in braces: int32_t Table[5] = { 0, 2, 4, 8, 16 }; char Encode[ 4 ] = { z, y, x, w }; 11

Storage Classes extern -- the variable or function is visible outside the program module (file) register -- the variable is used a lot and is a hint to the compiler the allocate in a hardware CPU register, if possible static -- the variable or function is not visible outside the program module 12

Assignment Statements X = A + B + C * ( D / E ); StartTime = GetCurrentTime(); 13

Conditional Statements if ( A == B ) { StartTime = GetCurrentTime(); }; if ( A <= B ) { Foo = 24; } else { Foo = 32; }; 14

Conditional Operators Relational operators: ==,!= <>, <, <=, =>, > Bitwise operators: &,, ^ Logical operators: &&,,! 15

Iterative Statements (for) for ( E1; E2; E3 ) {... }; E1 evaluated first E2 evaluated at the beginning of the loop E3 evaluated at the end of the loop for ( i = 0; i < K; i++ ) { Sum = Sum + Data[ i ]; }; 16

Iterative Statements (while, do) Simple loops while tests at the beginning do tests at the end while (1) { } Task1_Execute(); Task2_Execute(); 17

Selection Statements (switch) switch ( GateState ) { case On: Foo = 23; break; case Off: Foo = 45; break; default: Foo = 67; }; 18

Functions int Sub1( int A, int B, char S ) {...... return ( B + A ); } X = Sub1( 4, 5, B ); 19