Type compatibility and pointer operation

Slides:



Advertisements
Similar presentations
For(int i = 1; i
Advertisements

Factorial Preparatory Exercise #include using namespace std; double fact(double); int fact(int); int main(void) { const int n=20; ofstream my_file("results.txt");
Class 15 - Overhead 11Object Oriented Programming Using C #define t_circle 1 #define t_rectangle 2 struct circle_shape {short type; double x,y; double.
Structures Spring 2013Programming and Data Structure1.
Structs CSE 2451 Rong Shi. Structures Structure – one or more values, called members, with possibly dissimilar types that are stored together – Group.
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
Extending Type Systems in a Library Yuriy Solodkyy Jaakko Järvi Esam Mlaih.
Built into qsort is a function that can swap two given array elements.
The Cn Language over view The Cn language strongly on ANSI C. So if you are familiar with ANCI it is not so tough to deal with Cn language. Basic Data.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Structures and Unions in C Alan L. Cox
Introduction to Computers and Programming Class 24 Structures (structs) Professor Avi Rosenfeld.
 constant represented by a name, just like a variable, but whose value cannot be changed  The const keyword precedes the type, name, and initialization.
Advanced Programming Constants, Declarations, and Definitions Derived Data Types.
CE-2810 Dr. Mark L. Hornick 1 “Classes” in C. CS-280 Dr. Mark L. Hornick 2 A struct is a complex datatype that can consist of Primitive datatypes Ints,
Detecting Type-Based Alias Analysis Violations in C Iain Ireland (University of Alberta) Jose Nelson Amaral (University of Alberta) Raul Silvera (IBM Canada)
Overview Working directly with memory locations is beneficial. In C, pointers allow you to: change values passed as arguments to functions work directly.
Generic Programming in C
Using SMGCPA for the Detection of Memory Safety Bugs in the Linux Kernel Anton Vasilyev.
Struct Properties The C struct mechanism is vaguely similar to the Java/C++ class mechanisms: - supports the creation of user-defined data types - struct.
CSE 3302 Programming Languages
Data types Data types Basic types
UNIT – I Linked Lists.
Agenda Make Utility Command Line Arguments in Unix
Structures and Unions in C
Object Oriented Programming
Structs & typedef Already seen in tirgul.
C Basics.
Struct Properties The C struct mechanism is vaguely similar to the Java/C++ class mechanisms: - supports the creation of user-defined data types - struct.
Structures.
Lecture 6 C++ Programming
Sequences 9/18/ :20 PM C201: Linked List.
Templates.
The Bag and Sequence Classes with Linked Lists
CMSC 104, Section 4 Richard Chang
S. Kiran, PGT (CS) KV, Malleswaram
Advanced Programming Basics
Lecture 8.
Array of Structures A structure holds only one record But a record
Pointers, Dynamic Data, and Reference Types
Data Structures and Algorithms
CSC 253 Lecture 7.
Classes and Objects.
Prof. Bhushan Trivedi Director GLS Institute of Computer Technology
Variables in C Declaring , Naming, and Using Variables.
EGR 2261 Unit 12 structs Read Malik, Chapter 9.
Pointers Chapter 11 Copyright © 2008 W. W. Norton & Company.
Pointers Pointers point to memory locations
2. Second Step for Learning C++ Programming • Data Type • Char • Float
This is… 2 DOUBLES 4→10 EARLY NUMBER SENSE.
Programming Language C Language.
Symbol table lookup & install
Starting to think about objects...
Lab4 problems More about templates Some STL
Interface between frontend and backend
Programming Languages and Paradigms
Exam #1 February 23rd (Next Friday)
SYMBOL TABLE Chuen-Liang Chen Department of Computer Science
ENERGY 211 / CME 211 Lecture 8 October 8, 2008.
CSCE 206 Lab Structured Programming in C
nested-name-specifier
Struct Properties The C struct mechanism is vaguely similar to the Java/C++ class mechanisms: - supports the creation of user-defined data types - struct.
Pointers and pointer applications
C++ parse analysis Save and restore parser state
This is… 7 DOUBLES 12→20 EARLY NUMBER SENSE.
Abstract Data Types Stacks CSCI 240
Structs & typedef Already seen in tirgul.
C++ Parse Analysis Introduction
Temporary type Kei Hasegawa
Default argument Kei Hasegawa.
Presentation transcript:

Type compatibility and pointer operation Kei Hasegawa 2018.10.11

Type compatibility Refer to ISO IEC C98/C99 for restrict definition. Roughly say, Type T1 is compatible with type T2 <-> extern T1 x; extern T2 x; is not error.

Array compatibility typedef int T1[]; typedef int T2[10]; extern T1 x; is not error. So, Type int [] is compatible with type int [10]

Function compatibility typedef void T1(int (*)(int), double (*)[]); typedef void T2(int (*)(), double (*)[2]); typedef void T3(); extern T1 x; extern T2 x; extern T3 x; is not error. So, Type void (int (*)(int), double (*)[]), type void (int (*)(), double (*)[2]) and type void () are compatible with for each other.

Tagged type compatibility struct S; extern struct S x; // incomplete type struct S { int a; }; extern struct S x; // complete type is not error. So, incomplete struct S is compatible with complete struct S.

Pointer compatibility Type T1 is compatible with type T2 <-> extern T1 *x; extern T2 *x; is not error.

Canonical rule of pointer operation Pointers to qualified or unqualified versions of compatible types shall have the same representation and alignment requirements. For example, int* p and const int* q shall have the same representation and alignment requirements. So that’s why comparison int* p and const int* q or assignment like q = p are valid. But p = q is error in sense of discarding qualifier. For int** p2 and const int** q2, any operation is not defined. i.e. it’s error. Type of p2 is pointer to int* and type of q2 is pointer to const int*, but int* is not compatible with const int*.

Pointer and pointer operation – applied canonical rule p – q p < q, p > q, p <= q, p >= q p == q, p != q possible to compare void* and 0 expr ? p : q can be void* or 0 p = q