C And C 2013-Books Pdf

C and C 2013
24 Sep 2020 | 4 views | 0 downloads | 67 Pages | 2.76 MB

Share Pdf : C And C 2013

Download and Preview : C And C 2013

Report CopyRight/DMCA Form For : C And C 2013



Transcription

Part 1 Overview 2, file structure 2, simple program 2. a few details 3, hands on enter the program on page 2 4. part 2 Language Elements 5, functions 5, statements 7. hands on a larger program 9, part 3 Style and Idioms 10. arguments 10, pointers and returning values 11, arrays pointer arithmetic and array arguments 11.
hands on sorting strings 14, part 4 Structured Types 15. typedef 15, putting it together array of struct 17. hands on sorting employee records 18, part 5 Advanced Topics 19. preprocessor 19, function pointers 20, traps and pitfalls 21. hands on generalizing a sort 23, part 6 Programming in the Large 24.
file structure revisited 24, maintainability 24, portability 25. hiding the risky parts 25, performance vs maintainability 26. hands on porting a program from UNIX 27, part 7 Object Oriented Design 28. identifying objects 28, object relationships 28, entities vs actions 29. example event driven program 29, design task simple event driven user interface 31.
part 8 OOD and C 32, language elements 32, example 32. hands on implementation 35, part 9 Object Oriented Design and C 36. OOD summary 36, objects in C 36, stream I O 38, differences from C 39. hands on simple example 41, part 10 Classes in More Detail 42. constructors and destructors 42, inheritance and virtual functions 43.
information hiding 43, static members 43, hands on adding to a class 45. part 11 style and idioms 46, access functions 46, protected vs private 46. usage of constructors 47, hands on implementing a simple design 49. part 12 Advanced Features 50, mixing C and C 50, overloading operators 50. memory management 51, multiple inheritance 52, cloning 53.
hands on 3 D array class 55, part 13 Design Trade Offs 56. case study vector class 56, defining operators vs functions 56. when to inline 56, the temporary problem 57, hands on vector class using operators 58. part 14 More Advanced Features and Concepts 59, templates 59. exceptions 60, virtual base classes 60, future feature name spaces 61.
libraries vs frameworks 61, i n d e x 62, C was developed in the 1970s to solve the problem of implementing the UNIX. operating system in a maintainable way An unexpected consequence was that UNIX. also became relatively portable Consequently some think of UNIX the first computer. virus but this is erroneous There are major technical differences between UNIX and a. C was designed a time when computer memories were small especially on the. low end computers for which UNIX was originally designed At the same time. compiler writing techniques were not as well developed as they are today Most code. optimization tricks of the time was oriented towards making FORTRAN floating point. programs as fast as possible and tricks used in modern compilers to keep registers in. variables as long as possible and to minimize the number of times an array index. must be computed to give two examples were still to be developed. As a consequence to make C viable for operating system development the. language has many features which are unsafe and with today s compiler technology. unnecessary Even so only the best compilers typically found on UNIX systems. implement really good code generation and typical PC compilers are not as good. Part of the reason is to be found in the instruction set of the Intel 80x86 processor. line which has very few general purpose registers and a large range of equivalent. instructions to choose from in some circumstances, These notes introduce C with a modern style of programming emphasizing. avoidance of the most risky features while explaining where their use may still be. appropriate The intended audience is experienced programmers who may be used to. a more structured language differences from such languages are noted where. appropriate or useful, As a bridge to C object oriented design is introduced with C as a vehicle This. illustrates how object oriented design is a separate concept from object oriented. languages even though an object oriented language is clearly the better. implementation medium for an object oriented design. The notes are divided into 14 parts each of which is followed by a hands on or. discussion session The first half is about C concluding with object oriented design. and how it relates to C C is introduced as a better way of implementing object. oriented designs, Since this information was originally compiled in 1994 some details may be. dated Watch for new versions as errors and omissions are corrected In the 2013. edition I eliminate some of the obvious anachronisms including references to. languages no longer in wide use, The notes are intended to supply enough material to absorb in a week some.
sources of further information include, Brian W Kernighan and Dennis M Richie The C Programming Language 2nd edition Prentice Hall. Englewood Cliffs NJ 1988 ISBN 0 13 110362 8, Margaret A Ellis and Bjarne Stroustrup The Annotated C Reference Manual Addison Wesley. Reading MA 1990 ISBN 0 201 51459 1, Stanley B Lippman C Primer 2nd edition Addison Wesley Reading MA 1989 ISBN 0 201. Grady Booch Object Oriented Design with Applications Addison Wesley Reading MA 1991 ISBN. 0 201 56527 7, acknowledgement, Andr s Salamon proof read an early version and suggested some clarifications. Part 1 Overview, file structure, C source files are organized as compilable files and headers A header file contains.
declarations a compilable file imports these declarations and contains definitions. A definition tells the compiler what code to generate or to allocate storage for a. variable whereas a declaration merely tells the compiler the type associated with a. name Headers are generally used for publishing the interface of separately compiled. In UNIX it s usual to end compilable file names with c and headers with h. A compilable file imports a header by a line such as usually for system headers. include stdio h, or usually for your own headers, include employees h. The difference between the use of and will be explained later. When the header is imported it s as if the include line had been replaced by the. contents of the named file, caution in C this is only a convention but one that should not be. broken the header could contain anything but it should only contain. declarations and comments if your code is to be maintainable. simple program, Only a few more points are needed to write a program so here s an example. include stdio h, void main int argc char argv, for i 0 i argc i. printf command line argument d s n i argv i, The first line imports a system header for standard input and output The second.
line is the standard way of declaring a main program A main program can return a. result of type int though this one doesn t actually return a value hence the void. The main program has two arguments the first of which is a count of command. line arguments from the command that started the program The second is a pointer to. an array of strings each of which is a separate command line argument By. convention the first string is the name of the program Note the syntax a is used. to declare a pointer and an empty pair of square brackets is used to denote a variable. sized array, The next thing to notice is the use of curly brackets for a begin end block. The main program declares a variable i and uses it as a loop control variable. Note the convention of counting from zero and using a test to terminate the. loop This convention is useful because C arrays are indexed from zero. The for loop control actions must be in parentheses and the initialization test and. increment are separated by semicolons, The body of the loop is a single statement in this case so no are needed to. group statements into the body, The body of the loop uses library function printf to produce output The first. string is used to format the arguments that follow The d in the format string causes. the next argument to be printed as a decimal integer and the s causes the final. argument to be printed as a string A n terminates a line of output. what does the program do No prizes for the answer, a few details. In C there is no distinction between functions that return a value and functions that. don t some languages call the latter procedures other than that a function. returning a type void can t be used where a value is expected There is a distinction. between statements and expressions but it is usually possible to use an expression as. a statement For example the following is legal C code note use of for. void main int argc char argv, i 1 this is an expression.
This is a silly example but there are cases where the result of an expression is not. needed just its side effect i e what it changes in the global environment Functions. that do not return a result are declared to return type void which is a general non type. also used to specify pointers that can t be dereferenced among other things. A few examples of expressions that might be considered statements in other. assignment done with in C so for example it s possible to do a string of. initializations in one go comparison for equality uses. i j 0 j 0 is an expression returns new value of j, procedure call always a function call in C even if no value is returned on the. other hand a value returning function can be called as if it were a procedure call. in which case the value is thrown away, increment var name and decrement var name the exact behaviour of these. constructs is too complex for an introduction they are explained more fully later. Unlike some languages e g LISP Algol 68 that treat everything as expressions. most other statements in C cannot be used to return a value These include selection. if and switch loops while for and do while the latter tests the condition at the. end ensuring there is always at least one iteration and blocks. hands on enter the program on page 2, aims learn to use the editor and compiler get a feel for C syntax. caution C is case sensitive be careful to observe capitalization for. example r and R are different variable names but someone. maintaining your code won t thank you if you exploit this feature. part 2 Language Elements, Functions in C do not have to have a return type specified the default is int It is a. good convention however to put the type in even in this case Functions that are called. as procedures i e return no value are declared as returning void. A function as we shall see later can be stored as a variable or passed as a. parameter so a function has a type like any other value. The complete specification of the function s type is given by a prototype. specifying the function s return type name and argument types its type signature. for example, void sort int data int n, It is permissible to leave out the names of the parameters.
void sort int int, This is not good practice names make the purpose of the parameters more obvious. Prototypes are usually used in headers but can be used if the function is called. before it s defined As we shall see later prototypes are also used in C class. declarations, In C parameter passing is by value values of arguments are copied to the. function To pass by reference Pascal var parameters you create a pointer to the. parameter in the call This is done using the operator which creates a pointer to its. operand For example, void swap int a int b, called somewhere. int first second, give them values then, swap first second. Inside the function a and b are pointers to ints int To access their values in. the function they must be dereferenced The Pascal dereference operator is C s is. A notational convenience you write a variable in a declaration the same way as you. write it when you dereference it This makes it easy to remember where to put the. In the call the variables first and second are not of a pointer type so a pointer to. the values they hold has to be created explicitly using the operator. What would happen if the example changed as follows. void swap int a int b, called somewhere, int first second.
give them values, swap first second what does this actually do. Terminology corner the parameter where you declare or define a function is. technically a formal parameter and where you call it the value supplied is an. actual paramter In C to be different a formal parameter is just called a. parameter and the value passed in is called an argument. To return a value from a function, return value immediately exits function. Functions returning void can use return with no value to exit immediately e g on. discovering an error condition Functions can only be global though their names can. be restricted to file scope by declaring them static see Part 6 for more on static. A few C types have sneaked in without introduction so let s remedy that now. We ve already seen the types int integer and int pointer to integer. These types correspond to integer types in most other languages Though it is. possible for different compilers on the same machine to have different conventions as. to the size of a given type integers are commonly 32 bits In C it is often assumed. that an int is the size of a machine address though when we reach the portability. section in Part 6 we shall see that this can be a problem. C was designed a time when computer memories were small especially on the C Primer 2nd edition Addison Wesley Reading MA 1989 ISBN 0 201 17928 8 Grady Booch Object Oriented Design with Applications Addison Wesley Reading MA 1991 ISBN 0 201 56527 7 acknowledgement Andr s Salamon proof read an early version and suggested some clarifications Part 1 Overview

Related Books

Blevins 1995 The syllable in phonological theory In

Blevins 1995 The syllable in phonological theory In

Blevins 1995 The syllable in phonological theory In Goldsmith J ed Handbook of phonological theory Oxford Blackwell Crosslinguistic variation in syllable types V CV CVC VC CCV CCVC CVCC VCC CCVCC CVCCC Hua Cayuvava Mazateco Mokilese Sedang Klamath

An Introduction to English Phonology

An Introduction to English Phonology

Our phonological knowledge is not something we can necessarily access and talk about in detail we often have intuitions about language without knowing where they come from or exactly how to express them But the knowledge is certainly there For instance speakers of English will tend to agree that the word snil is a possible but non existent word whereas fnil is not possible as the

National Crane 500E2 Series Manitowoc Cranes

National Crane 500E2 Series Manitowoc Cranes

National Crane 500E2 Series Product Guide Features 16 3 t 18 USt rating 1 6 m 71 ft three section boom 2 Self lubricating Easy Glide wear pads Internal anti two block Features Three section boom With a capacity of 16 3 t 18 USt the Series 500E2 is equipped with a three section 21 6 m 71 ft boom The long boom allows the operator to perform more lifts without the use

OWNERS MANUAL INSTALLATION OPERATION amp MAINTENANCE

OWNERS MANUAL INSTALLATION OPERATION amp MAINTENANCE

OWNERS MANUAL INSTALLATION OPERATION amp MAINTENANCE INSTRUCTIONS 1128 Sherborn Street Corona CA 92879 2089 951 281 1830 FAX 951 281 1879 IHR SERIES HEAVY DUTY RANGES AND OVEN All Imperial Mfg Co equipment is manufactured for use with the type of gas specified on the rating plate and for installation in accordance with ANSI Z223 1 NFPA 54 latest edition of the National Fuel Gas

Service Manual farnell com

Service Manual farnell com

This manual contains important safety instructions Keep this manual handy for reference The Imperial Series also supports software which relies on basic contact closure signals such as the built in UPS Service in Windows NT you will need to purchase a special cable for this type of application The major functions of this type of software normally include the following To

Am lioration de la performance par la TPM 3M en France

Am lioration de la performance par la TPM 3M en France

Manufacturing and Supply Chain 3M 2007 All Rights Reserved S minaire Lean en France 11 d cembre 2009 Am lioration de la performance par la TPM 3M

3M des produits qui vous scotchent

3M des produits qui vous scotchent

3M le syst me de planification formelle et de budg tisation n a t mis en place que dans les ann es 80 et a toujours jou un r le secondaire dans la prise de d cision par le management Les directeurs avaient la conviction que la priorit tait d encourager les entrepreneurs qui travaillaient sur des activit s nouvelles Senior management primary role is to create an inter nal

STANDARD SPECIFICATIONS AND DETAILS Union Sanitary

STANDARD SPECIFICATIONS AND DETAILS Union Sanitary

Standard Specifications and Details SECTION 1 INTRODUCTION 1 01 INTRODUCTION The STANDARD SPECIFICATIONS for sanitary sewers shall govern requirements design and all work in connection with main and building sewer construction within the Union Sanitary District of Alameda County California District Information Bulletin applicable portions

SEWER STANDARD DRAWINGS INDEX TO COMPONENTS

SEWER STANDARD DRAWINGS INDEX TO COMPONENTS

sheet 21 long section standard sheet 22 w a e minimum detail sheet 23 typical air valve air valve adaptors sheet 24 cam lock scour fittings detail air valve adaptors sheet 25 private pump station to boundary shaft sheet 26 thrust anchorage table sheet 27 concrete pipe encasement sheet 28 earthing ring detal sheet 29 construction traffic pipe requirements sheet 30 gravity

STANDARD DE DONN ES INPN

STANDARD DE DONN ES INPN

dans sa version 1 2 1 Jomier et al 2016 standard national propre chaque th matique du SINP observations de biodiversit paysages espaces prot g s etc Cf article 2 du Protocole du SINP du 15 mai 2013 Occtax v2 mini 15 03 2018 6 30 Figure 1 Positionnement du standard de donn es occurrence de taxon au sein du SINP 2 Principe et notation Pour structurer les

European Technical Standard Order

European Technical Standard Order

ED Decision 2016 013 R Annex II ETSO C70b Page 12 of 160 Date 5 8 2016 European Aviation Safety Agency European Technical Standard Order Subject LIFE RAFTS 1 Applicability This ETSO provides the requirements which life rafts that are designed and manufactured on or after the date of this ETSO must meet in order to be identified with the applicable ETSO marking 2