Rudra Dutta CSC Spring 2007, Section 001

Slides:



Advertisements
Similar presentations
User Defined Functions
Advertisements

Functions Function: The strength of C language is to define and use function. The strength of C language is that C function are easy to define and use.
Spring Semester 2013 Lecture 5
Chapter Five Functions
Lecture 2 Introduction to C Programming
Introduction to C Programming
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved The switch Multiple-Selection Statement switch.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Storage & Linkage: Effects on Scope Rudra Dutta CSC Spring 2007, Section 001.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Debugging, Build and Version Control Rudra Dutta CSC Spring 2007, Section 001.
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Functions Top-down design Breaking a complex problem into smaller parts that we can understand is a common practice. The process of subdividing a problem.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
User defined functions
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
First Compilation Rudra Dutta CSC Spring 2007, Section 001.
Multi-dimensional Arrays and other Array Oddities Rudra Dutta CSC Spring 2007, Section 001.
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
Chapter 4 – C Program Control
Computer Science 210 Computer Organization
INC 161 , CPE 100 Computer Programming
Chapter 2 - Introduction to C Programming
Lecture 7: Repeating a Known Number of Times
Functions, Part 2 of 2 Topics Functions That Return a Value
Chapter 2 - Introduction to C Programming
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
Flow of Control.
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Computer Science 210 Computer Organization
Functions Inputs Output
Lecture 2: Logical Problems with Choices
Flow of Control.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Expressions Chapter 4 Copyright © 2008 W. W. Norton & Company.
Functions I Creating a programming with small logical units of code.
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Chapter 2 - Introduction to C Programming
CSI 121 Structured Programming Language Lecture 13 Functions (Part 1)
Chapter 4 - Program Control
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions Chapter 9 Copyright © 2008 W. W. Norton & Company.
Flow of Control.
Assignment Operators Topics Increment and Decrement Operators
Program Control Topics While loop For loop Switch statement
Chapter 2 - Introduction to C Programming
Assignment Operators Topics Increment and Decrement Operators
Lecture3.
Computer programming Lecture 3.
ECE 103 Engineering Programming Chapter 20 Change in Flow of Control
Chapter 2 - Introduction to C Programming
Chapter 4 - Program Control
Programming Languages and Paradigms
Introduction to C Programming
Functions I Creating a programming with small logical units of code.
Assignment Operators Topics Increment and Decrement Operators
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions, Part 2 of 42 Topics Functions That Return a Value
Functions, Part 2 of 3 Topics Functions That Return a Value
Rudra Dutta CSC Spring 2007, Section 001
Scope Rules.
Presentation transcript:

Rudra Dutta CSC 230 - Spring 2007, Section 001 Sequence Points Rudra Dutta CSC 230 - Spring 2007, Section 001

Sequence of Instructions Program consists of series of instructions Source code is specification of not only the instructions to execute but the sequence of execution However, “single” instructions of source code become sets of multiple actual instructions Even more so for a compact language such as C There is a limit to the power of specification of instruction sequence Formalized in the concept of “sequence points” Certain points in the execution sequence where all side effects of previous evaluations shall be complete, and no side effects of subsequent evaluations shall have taken place Copyright Rudra Dutta, NCSU, Spring, 2007

Sequence Points The call to a function, after the arguments have been evaluated The end of the first operand of the following operators: logical AND && logical OR || conditional ? comma , The end of a full declarator A declarator is the part of a declaration (definition or initialization) that is not the type Copyright Rudra Dutta, NCSU, Spring, 2007

Sequence Points The end of a full expression: an initializer the expression in an expression statement the controlling expression of a selection statement (if or switch) the controlling expression of a while or do statement each of the expressions of a for statement the expression in a return statement Immediately before a library function returns After the actions associated with each formatted input/output function conversion specifier Immediately before and immediately after each call to a comparison function, and also between any call to a comparison function and any movement of the objects passed as arguments to that call Copyright Rudra Dutta, NCSU, Spring, 2007

Example of Sequence Point Issue #include <stdio.h> #include <stdlib.h> int j; void func_1 (int i, int k) { for (j=0; j<i; j++) { printf ("%d ", j); } printf ("%d\n", k); int main () { int j; for (j=0; j<10; j++) { func_1 (j, j); } Copyright Rudra Dutta, NCSU, Spring, 2007

Example of Sequence Point Issue #include <stdio.h> #include <stdlib.h> int j; void func_1 (int i, int k) { for (j=0; j<i; j++) { printf ("%d ", j); } printf ("%d\n", k); int main () { /* int j; */ for (j=0; j<10; j++) { func_1 (j, j); } Copyright Rudra Dutta, NCSU, Spring, 2007

Example of Sequence Point Issue #include <stdio.h> #include <stdlib.h> int j; void func_1 (int i, int k) { /* int j; */ for (j=0; j<i; j++) { printf ("%d ", j); } printf ("%d\n", k); int main () { /* int j; */ for (j=0; j<10; j++) { func_1 (j, j); } Copyright Rudra Dutta, NCSU, Spring, 2007

Example of Sequence Point Issue #include <stdio.h> #include <stdlib.h> int j; void func_1 (int i, int k) { /* int j; */ for (j=0; j<i; j++) { printf ("%d ", j); } printf ("%d\n", k); int main () { /* int j; */ for (j=0; j<10; j++) { func_1 (++j, j); } Copyright Rudra Dutta, NCSU, Spring, 2007

Example of Sequence Point Issue #include <stdio.h> #include <stdlib.h> int j; void func_1 (int i, int k) { /* int j; */ for (j=0; j<i; j++) { printf ("%d ", j); } printf ("%d\n", k); int main () { /* int j; */ for (j=0; j<10; j++) { func_1 (j, ++j); } Copyright Rudra Dutta, NCSU, Spring, 2007

Expressions and Sequence Points Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored. i = i + 1; a[i] = i; i = ++i + 1; a[i++] = i; Copyright Rudra Dutta, NCSU, Spring, 2007

Function Calls and Sequence Points The order of evaluation of the function designator, the actual arguments, and subexpressions within the actual arguments is unspecified BUT there is a sequence point before the actual call Copyright Rudra Dutta, NCSU, Spring, 2007