The New C Standard (Excerpted material)

Similar documents
The New C Standard (Excerpted material)

The New C Standard (Excerpted material)

The New C Standard (Excerpted material)

The New C Standard (Excerpted material)

The New C Standard (Excerpted material)

The New C Standard (Excerpted material)

The New C Standard (Excerpted material)

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

The New C Standard (Excerpted material)

The New C Standard (Excerpted material)

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

Operators. Lecture 3 COP 3014 Spring January 16, 2018

The New C Standard (Excerpted material)

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Expressions and Precedence. Last updated 12/10/18

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

Review of the C Programming Language

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Chapter 3 Structure of a C Program

Review of the C Programming Language for Principles of Operating Systems

The New C Standard (Excerpted material)

Fundamentals of Programming Session 20

Programming in C++ 5. Integral data types

Introduction to C. Systems Programming Concepts

A flow chart is a graphical or symbolic representation of a process.

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

The New C Standard (Excerpted material)

Visual C# Instructor s Manual Table of Contents

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

LECTURE 3 C++ Basics Part 2

UNIT- 3 Introduction to C++

Operators & Expressions

1 Lexical Considerations

Information Science 1

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

The New C Standard (Excerpted material)

Operators in java Operator operands.

Arithmetic Operators. Portability: Printing Numbers

Engineering Computing I

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

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

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Infix to Postfix Conversion

Operators and Expressions:

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

Lexical Considerations

The New C Standard (Excerpted material)

Fundamental of C programming. - Ompal Singh

Type Checking. Prof. James L. Frankel Harvard University

Computers Programming Course 5. Iulian Năstac

Declaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.

CHAPTER 3 Expressions, Functions, Output

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

Operators and Type Conversion. By Avani M. Sakhapara Assistant Professor, IT Dept, KJSCE

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Unit 3. Operators. School of Science and Technology INTRODUCTION

Chapter 7. Additional Control Structures

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

Chapter 3: Operators, Expressions and Type Conversion

Language Reference Manual

DEPARTMENT OF MATHS, MJ COLLEGE

C Programming Language (Chapter 2 of K&R) Variables and Constants

Java Notes. 10th ICSE. Saravanan Ganesh

LECTURE 17. Expressions and Assignment

Informatics Ingeniería en Electrónica y Automática Industrial

Chapter 2: Using Data

Operators. Java operators are classified into three categories:

SECTION II: LANGUAGE BASICS

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

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

Tokens, Expressions and Control Structures

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Variables and Operators 2/20/01 Lecture #

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

The New C Standard (Excerpted material)

Chapter 7. Expressions and Assignment Statements ISBN

Chapter 2. Lexical Elements & Operators

Lecture 3. More About C

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

Axivion Bauhaus Suite Technical Factsheet MISRA

Have the same meaning as variables in algebra Single alphabetic character Each variable needs an identifier that distinguishes it from the others a =

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

Information Science 1

Java enum, casts, and others (Select portions of Chapters 4 & 5)

Fall, 2015 Prof. Jungkeun Park

Basics of Programming

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

3. Java - Language Constructs I

Expressions & Assignment Statements

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

C Programming a Q & A Approach

UNIT-2 Introduction to C++

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Data Types and Variables in C language

Lexical Considerations

Department of Computer Science

Programming for Engineers: Operators, Expressions, and Statem

Transcription:

The New C Standard (Excerpted material) An Economic and Cultural Commentary Derek M. Jones derek@knosof.co.uk Copyright 2002-2008 Derek M. Jones. All rights reserved.

unary-expression castexpression unary-expression: postfix-expression ++ unary-expression -- unary-expression unary-operator cast-expression sizeof unary-expression sizeof ( type-name ) unary-operator: one of & * + - ~! Commentary Note that the operand of unary-operator is a cast-expression, not a unary-expression. A unary operator usually refers to an operator that takes a single argument. Technically all of the operators listed here, plus the postfix increment and decrement operators, could be considered as being unary operators. Rationale Unary plus was adopted by the C89 Committee from several implementations, for symmetry with unary minus. multiplicativeexpression Other Languages Some languages (i.e., Ada and Pascal) specify the unary operators to have lower precedence than the multiplicative operators; for instance, -x/y is equivalent to -(x/y) in Ada, but (-x)/y in C. Most languages call all operators that take a single-operand unary operators. Languages that support the unary + operator include Ada, Fortran, and Pascal. Some languages use the keyword NOT rather than!. In the case of Cobol this keyword can also appear to the left of an operator, indicating negation of the operator (i.e., NOT < meaning not less than). Coding Guidelines Coding guidelines need to be careful in their use of the term unary operator. Its meaning, as developers understand it, may be different from its actual definition in C. The operators in a unary-expression occur to the left of the operand. The only situation where a developer s incorrect assumption about precedence relationships might lead to a difference between predicted and actual behavior is when a postfix operator occurs immediately to the right of the unary-expression. Dev?? Except when sizeof ( type-name ) is immediately followed visually by a token having the lexical form of an additive operator, if a unary-expression is not immediately followed by a postfix operator it need not be parenthesized. macro def-?inition expression Although the expression sizeof (int)-1 may not occur in the visible source code, it could easily occur as the result of macro replacement of the operand of the sizeof operator. This is one of the reasons behind the guideline recommendation specifying the parenthesizing of macro bodies (without parentheses the expression is equivalent to (sizeof(int))-1). Example 1 struct s { 2 int x; 3 }; 4 struct s *a; 5 int x; 6 2 v 1.1 January 30, 2008

100,000 unary - decimal-constant 10,000 hexadecimal-constant unary Occurrences 1,000 100 10 1 0 16 32 64 100 128 150 200 255 Numeric value 0 16 32 64 100 128 150 200 255 Numeric value Figure.1: Number of integer-constants having a given value appearing as the operand of the unary minus and unary ~ operators. Based on the visible form of the.c files. 7 void f(void) 8 { 9 x<-a->x; 10 x<--a->x; 11 x<- --a->x; 12 x<- - --a->x; 13 14 sizeof(long)-3; /* Could be mistaken for sizeof a cast-expression. */ 15 (sizeof(long))-3; 16 sizeof((long)-3); 17 } Usage See the Usage section of postfix-expression for ++ and -- digraph percentages. postfixexpression Table.1: Common token pairs involving sizeof, unary-operator, prefix ++, or prefix -- (as a percentage of all occurrences of each token). Based on the visible form of the.c files. Token Sequence % Occurrence of First Token % Occurrence of Second Token Token Sequence % Occurrence of First Token! defined 2.0 16.7! ( 14.5 0.5 *v --v 0.3 7.8 -v identifier 30.2 0.4 -v floating-constant 0.3 6.7 *v ( 9.0 0.4 *v ++v 0.5 6.3 ~ integer-constant 20.1 0.2! --v 0.2 4.8 ++v identifier 97.3 0.1 -v integer-constant 69.0 4.1 ~ identifier 56.3 0.1 &v identifier 96.1 1.9 ~ ( 23.4 0.1 sizeof ( 97.5 1.8 +v integer-constant 49.0 0.0 *v identifier 86.8 1.0 --v identifier 97.1 0.0! identifier 81.9 0.8 % Occurrence of Second Token January 30, 2008 v 1.1 3

Table.2: Occurrence of the unary-operators, prefix ++, and prefix -- having particular operand types (as a percentage of all occurrences of the particular operator; an _ prefix indicates a literal operand). Based on the translated form of this book s benchmark programs. Operator Type % Operator Type % Operator Type % -v _int 96.0 ~ unsigned long 6.8! _long 2.7 *v ptr-to 95.3 &v int 6.2 ~ unsigned char 2.5 +v _int 72.2 ~ unsigned int 6.0 &v unsigned char 2.4 --v int 54.7 +v unsigned long 5.6! unsigned long 2.1! int 50.0 +v long 5.6 ~ long 2.0 ~ _int 49.3 +v float 5.6 ++v unsigned char 1.9 &v other-types 45.1! other-types 5.6 ~ _unsigned long 1.7 ++v int 43.8 ++v unsigned long 5.2 ~ _unsigned int 1.7 ++v ptr-to 33.3 &v struct * 4.9! unsigned char 1.6 ~ int 28.5 --v unsigned long 4.7 ~ other-types 1.6 --v unsigned int 22.1! unsigned int 4.7 -v _double 1.4! ptr-to 20.1 *v fnptr-to 4.1 -v other-types 1.3 --v ptr-to 14.6 &v unsigned long 4.0 ++v long 1.2 &v struct 13.9 --v other-types 4.0 -v int 1.2 &v char 13.1 &v long 3.4! _int 1.2 ++v unsigned int 12.6 &v unsigned int 3.0 ++v unsigned short 1.1 +v int 11.1 &v unsigned short 2.9 &v char * 1.1! char 9.2! enum 2.9 v 1.1 January 30, 2008

References January 30, 2008 v 1.1