DOC PREVIEW
U of I CS 241 - Crash course in C

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS241Crash course in CCrash?Slide 5Slide 6Linkage & ScopeLinkageutil.cmain.cSlide 11Declarations to library functions?C Compilergcc Gnu CompilerC VariantsPointersSlide 17int *pSlide 19char **argvchar ***argvArgument ArraysCharacter stringsstrcmpWhy is this bad?Ans: Understand storageIdentifies & Linkage SummaryIdentifiersLinkage classesStorage classes: static and automaticCS241Introduction To CLawrence AngraveCrash course in CCrash char *p; p=0;*p=4?char * search(char*) {char result[100];… do stuffreturn result;}?static int debug=1;main(…){}?int counter() {static int c=1;printf(“The value of c is %x”,&c);return c++;}Linkage & ScopeLinkageIdentifiers (variables & functions) visible to another c file?Main.c = Compilation unitMyutils.c = Another compilation unitStatic : No!util.cstatic int notthisone;int runsuperfast=0;void die(char*) { static int privatecounter; fprintf(stderr,mesg); exit(1);}main.c Refer to runsuperfast and die?extern int runsuperfast;void die(char *mesg);main.c Refer to runsuperfast and die?void die(char *); // declaration!extern int runsuperfast;Declarations to library functions?#include <stdio.h>#include <stdlib.h>#include “myutils.h”C Compilergcc Gnu CompilerMany options!man gccThree for the price of onePreprocessorCompilerLinkerC VariantsC99 - A ‘nicer’ C/* Multi-line comments */// line comment (Not allowed in C89)Mix variable declarations & code inside functionsPointersPointersHow to shoot yourself in the foot and not realize itint *pQ. What is p?How much storage is required for p?Where is p in memory?int *pWhat is the value of p == &*p; p[0] == *pchar **argvExplain this to your neighborchar ***argvExplain this to your neighborWhen would you use it?Argument Arrays An argument array is an array of pointers terminated by a NULL pointer.Each element of the array is of type char * and represents a string.Character stringsBasic support in Compiler for string constants and string pointersEverything else is a library functionstrcmpstrncmpstrlenstrcatstrcmpstrcmp(“Hello”,”Hello”) returns what?strcmp(“1”,”2”) returns what?Why is this bad?char *p=“Hello”;strcpy(p,” World”);Ans: Understand storageIdentifies & Linkage SummaryIdentifiers“Identifier” denotes an object: a function, a tag, member of a structure, etc. We mainly consider identifiers associated with functions and variablesScope is a region of program text where identifier is used Identifiers declared more than once may refer to the same object because of linkageEach identifier has a linkage class of external, internal or none. An identifier representing an object has a linkage class related to storage class (storage duration).Linkage classes Linkage class determines whether variables can be accessed in files other than the one in which they are declared. Internal linkage class means they can only be accessed in the file in which they are declared. External linkage class means they can be accessed in other files. Variables declared outside any function and function name identifiers have external linkage by default.They can be given internal linkage with the key word static . Variables declared inside a function are only known inside that function and are said to have no linkage.Storage classes: static and automatic Static storage class refers to variables that, once allocated, persist throughout the execution of a program. Automatic storage class refers to variables which come into existence when the block in which they are declared is entered and are discarded when the defining block is exited. Variables declared inside a function have automatic storage class unless they are declared to be static.These are usually allocated on the program stack. Variables defined outside any functions have static storage class. The word static has two meanings is C.One is related to storage class and the other to linkage


View Full Document

U of I CS 241 - Crash course in C

Documents in this Course
Process

Process

28 pages

Files

Files

37 pages

File I/O

File I/O

52 pages

C Basics

C Basics

69 pages

Memory

Memory

23 pages

Threads

Threads

14 pages

Lecture

Lecture

55 pages

C Basics

C Basics

24 pages

Signals

Signals

27 pages

Memory

Memory

45 pages

Threads

Threads

47 pages

Threads

Threads

28 pages

LECTURE

LECTURE

45 pages

Threads

Threads

30 pages

Threads

Threads

55 pages

Files

Files

37 pages

SIGNALS

SIGNALS

22 pages

Files

Files

37 pages

Threads

Threads

14 pages

Threads

Threads

13 pages

Load more
Download Crash course in C
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Crash course in C and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Crash course in C 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?