Practical C Issues:! Preprocessor Directives, Multi-file Development, Makefiles. CS449 Fall 2017
|
|
- Ruby Barrett
- 6 years ago
- Views:
Transcription
1 Practical C Issues:! Preprocessor Directives, Multi-file Development, Makefiles CS449 Fall 2017
2 Multi-file Development
3 Multi-file Development Why break code into multiple source files? Parallel development involving multiple authors Quicker compilation (only compile modified file) Modularity (can reuse object file / library) Encapsulation (easier to read / maintain) Use smallest scope to enforce encapsulation Avoids polluting global namespace Minimizes scope of code to find all uses of symbol But sometimes scopes must cross file boundaries... Then same symbol must be declared in all relevant source files
4 Block / Function Scope Scope: Local (function or block of code) Lifetime: Automatic (duration of function) Static (duration of program) void foo( ) { } int x; // automatic static int y; // static x = y =
5 Internal Linkage Scope Scope: File Lifetime: Static (duration of program) static int x; void foo( ) { x = } Void bar( ) { x = }
6 External Linkage Scope Scope: Program (multiple files) Lifetime: Static (duration of program) extern used to declare vars in other files File A File B int x; extern int x; void foo() { } void foo(); B declares x and foo defined in A
7 Multi-file Example int x = 0; a.c b.c #include <stdio.h> int f(int y) { return x+y; } /* Declarations for symbols defined in other files */ extern int x; int f(int); int main() { x = 1; printf("%d", f(2)); return 0; }
8 Multi-file Example thoth$ gcc c a.c b.c thoth$ gcc a.o b.o thoth$./a.out 3
9 Pitfall: Missing Definitions a.c // Missing x definition b.c #include <stdio.h> int f(int y) { return y; } /* Declarations for symbols defined in other files */ extern int x; int f(int); int main() { x = 1; printf("%d", f(2)); } return 0;
10 Pitfall: Missing Definitions thoth$ gcc c a.c b.c thoth$ gcc a.o b.o./b.o: In function `main': b.c:(.text+0x6): undefined reference to `x' collect2: ld returned 1 exit status Linker cannot find x in symbol table when it tries to resolve x in x = 1; inside b.c
11 Pitfall: Missing Declarations int x = 0; a.c b.c #include <stdio.h> int f(int y) { return x+y; } /* Missing declarations for x and int f(int) */ int main() { x = 1; printf("%d", f(2)); } return 0;
12 Pitfall: Missing Declarations thoth$ gcc c a.c b.c./b.c: In function main :./b.c:5: error: x undeclared Compiler must know there is an externally defined x and its type is int to generate code
13 Declarations and Definitions Definitions: Put into individual C (.c) files Function definitions: ends up in text section of.o file Variable definitions: ends up in data section of.o file One symbol must be defined in only one C file Declarations: Put into header (.h) files è #included in any C file using the symbols Function declarations Variables declarations (using extern) Type definitions (e.g. struct definitions) #defines
14 Declarations and Definitions mymalloc.h // Declarations void *my_malloc(int size); mymalloc.c // Definitions static void *head; void my_free(void *ptr); Why wasn t head declared in mymalloc.h? void *my_malloc(int size) {... } void my_free(void *ptr) {... }
15 Including a Header File Insert header In each C file using my_malloc, my_free: main.c #include mymalloc.h // insert header int main() { my_malloc( ); } foo.c #include mymalloc.h // insert header int foo() { my_free( ); }
16 Compiling Multiple Files Compiling: gcc mymalloc.c main.c foo.c Why not also compile mymalloc.h? A. Header does not define any symbols Contains only declarations to help compiler Nothing to generate an object file out of (Code / data segment would be empty) Hence nothing to compile
17 Makefiles:! Easy Multi-file Development
18 Makefile A script interpreted by the GNU Make utility to build projects containing multiple files Design Goal: on a source / header file modification, perform the smallest set of actions required By expressing what files depend upon others Composed of a collection of rules which look like target: dependencies action That is a single <tab> before action, not spaces! Script invoked by: make <target> If no target given, first target in script built by default
19 Makefile malloctest: mymalloc.o mallocdriver.o gcc o malloctest mymalloc.o mallocdriver.o mymalloc.o: mymalloc.c mymalloc.h gcc c mymalloc.c mallocdriver.o: mallocdriver.c mymalloc.h gcc c mallocdriver.c clean: rm f *.o malloctest
20 Dependency Graph malloctest mymalloc.o mallocdriver.o mymalloc.c mymalloc.h mallocdriver.c
21 Build from scratch Using a Makefile thoth $ ls Makefile mallocdrv.c mymalloc.c mymalloc.h thoth $ make gcc -c mymalloc.c gcc -c mallocdrv.c gcc -o malloctest mymalloc.o mallocdrv.o thoth $ make make: `malloctest' is up to date. Partial build after modifying mymalloc.c thoth $ touch mymalloc.c thoth $ make gcc -c mymalloc.c gcc -o malloctest mymalloc.o mallocdrv.o
22 Defining Variables in Makefiles Works like macros (text replacement) Syntax: <name> :=... or <name> =... Example: Instead of: malloctest: mymalloc.o mallocdriver.o gcc o malloctest mymalloc.o mallocdriver.o Can do: OBJECTS = mymalloc.o mallocdriver.o malloctest: $(OBJECTS) gcc o malloctest $(OBJECTS)
23 Automatic Variables The file name of the target. E.g.: malloctest: $(OBJECTS) gcc o $@ $(OBJECTS) $<: The name of the first prerequisite. E.g.: mymalloc.o: mymalloc.c mymalloc.h gcc c $< $^: The names of all prerequisites. E.g.: malloctest: $(OBJECTS) gcc o $@ $^
24 Pattern Matching Character % is a wildcard for any string Example: %.o: %.c gcc c $< -o $@ What it means: For all targets matching <some string>.o Dependency is <that string>.c Action is gcc c <that string>.c o <that string>.o Rule is used to produce any.o file from.c file
25 Concise Makefile malloctest: mymalloc.o mallocdriver.o gcc -o $^ %.o: %.c gcc -c $< -o mymalloc.o: mymalloc.h mallocdriver.o: mymalloc.h clean: rm -f *.o malloctest
26 Make Utility Options Usage: make [-f makefile] [options] [targets] -f makefile: Makefile to interpret targets: Targets to be built Options: <name> = <value>: Define a variable. -C <dir>: Change to directory <dir> before building. -n: Dry run. Just print commands and don t execute. -d: Debug mode. Print verbose information.
27 Preprocecessor Directives:! Easy Manipulation of Source Code
28 #include Copies the contents of specified file into current file #include < >: file in standard include location Usually /usr/include #include : file in current directory or specified paths Paths specified using the I option If main.c has following includes: #include <stdio.h> #include myheader.h and is compiled using gcc I ~/local/include main.c stdio.h under /usr/include myheader.h under current directory or ~/local/include
29 #define Defines macros Macro: rule that specifies textual replacement of one string for another Often used to assign names to constants #define PI #define MAX 10 float f = PI; for(i=0;i<max;i++)
30 #define Good macros are generic (do not make assumptions about inputs) Good: #define MAX(a,b) (a > b)? a : b Only assumes a can be compared to b Not so good: #define SWAP(a,b) {int t=a; a=b; b=t;} Makes assumption that types are int Better #define SWAP(T,a,b) {T t=a; a=b; b=t;}
31 #if #if <condition known to preprocessor> // Some code #endif Preprocessor emits code between #if directive and #endif directive to the compiler only if condition is true Condition evaluated at preprocessing time (cf. C if statement is evaluated at execution time) What does preprocessor know? Constants (0, 1, 2, Linux, x86, ) Values of #defined variables Arithmetic (+, -, *, /, >, <, ==, &&,, )
32 Example #include <stdio.h> int main() { } #if 0 printf( This is not compiled\n ); I can doodle here when I am bored. #endif printf( This is compiled\n ); return 0;
33 Example 2 #include <stdio.h> #define LIBRARY_VERSION 7 int main() { } #if LIBRARY_VERSION >= 5 some_function_included_in_version_5(); printf( This is compiled\n ); #endif return 0;
34 #else #if <condition1> // Emitted if condition1 is true #elif <condition2> // Emitted if condition1 is false and condition2 is true #else // Emitted if neither is true #endif
35 #if defined #if defined Checks to see if a macro has been defined, but doesn t care about the value A defined macro might expand to nothing, but is still considered defined
36 Example #include <stdio.h> #define DEBUG int main() { } #if defined DEBUG printf( Some debug output\n ); #endif return 0;
37 #undef Undefines a macro: #include <stdio.h> #define DEBUG int main() { } #if defined DEBUG #endif printf( This is printed\n ); #undef DEBUG #if defined DEBUG printf( This is not\n ); #endif return 0;
38 Shortcuts for #if defined #if defined #ifdef #if!defined #ifndef
39 Uses of #if directive Enable / disable code specific to a library, OS, CPU, etc. Turn on / off different features of program Debugging: #ifdef DEBUG printf( ) #endif More flexible debugging //easier to modify functionality of PrintDebug later #ifdef DEBUG #define PrintDebug(args ) fprintf(stderr, args) #else #define PrintDebug(args ) #endif
40 Using #if to #include! Header Only Once Including same header twice can lead to compile errors Redefinition of the same struct type, etc.. Easy to stumble into with multiple levels of nested headers #ifndef _MYHEADER_H_ #define _MYHEADER_H_ Declarations only to be included once #endif
41 Command Line Defined Macros D: Defines variables from command line gcc o test DVERSION=5 test.c gcc o test DDEBUG test.c Allows tailoring of source code to specific versions and features from command line
42 Pre-Defined Macros Macro FILE LINE DATE TIME STDC GNUC VERSION unix i386 Meaning Current compiled file Current line number Current date Current time Defined if compiler supports ANSI C Defined if compiler is GNU C compiler Version of GNU C compiler Defined if OS is a UNIX compliant system Defined if CPU has x86 instruction set Many other macros
43 Other Preprocessor Details # - places quotes around macro argument #define CALL(f) { printf(#f); f(); } CALL(foo) { printf( foo ); foo(); } ## - concatenates two things in macro #define CALL(f) f ## _debug () CALL(foo) foo_debug() #error: Emit error message and exit #warning: Emit warning message #pragma: Change behavior of compiler
44 Error Direc4ve Example #include <stdio.h> #ifndef i386 #error "Needs x86 architecture." #endif int main() { // Some x86 specific code return 0; } >> gcc./error.c./error.c:3:2: error: #error "Needs x86 architecture. >> gcc m32./error.c Tests whether hardware plagorm is i386 (x86) and displays error Ini4ally fails because default compila4on target is x86_64 (and i386 is not defined) -m32 op4on changes target to x86, implicitly defining i386 #warning: allows compila4on but with warning message
45 Concatena4on Example #include <stdio.h> #ifdef i386 #define CALL(f) f ## _x86 () #else #define CALL(f) f ## _x86_64() #endif void foo_x86() { } printf( x86 binary executable\n"); void foo_x86_64() { } printf( x86_64 binary executable\n"); int main() { } CALL(foo); return 0; >> gcc./concat.c >>./a.out x86_64 binary executable >> gcc m32./concat.c >>./a.out x86 binary executable Calls different func4ons depending on target architecture When i386 macro is undefined: CALL(foo) calls foo_x86_64() When i386 macro is defined: CALL(foo) calls foo_x86() -m32 op4on implicitly passes -D i386 to preprocessor
46 Pragma Example #include <stdio.h> #pragma message "Compiling " FILE " using " VERSION int main() { } return 0; >> gcc./pragma.c./pragma.c:3: note: #pragma message: Compiling./pragma.c using (Red Hat ) Prints diagnos4c message during compila4on of file Note two pre-defined macros: FILE and VERSION Many more pragmas To control struct padding (e.g. #pragma pack(1) ) To control code op4miza4ons (e.g. #pragma omp parallel )
#include. Practical C Issues: #define. #define Macros. Example. #if
#include Practical C Issues: Preprocessor Directives, Typedefs, Multi-file Development, and Makefiles Jonathan Misurda jmisurda@cs.pitt.edu Copies the contents of the specified file into the current file
More informationPractical C Programming
Practical C Programming Advanced Preprocessor # - quotes a string ## - concatenates things #pragma h3p://gcc.gnu.org/onlinedocs/cpp/pragmas.html #warn #error Defined Constants Macro FILE LINE DATE TIME
More informationThe Preprocessor. CS 2022: Introduction to C. Instructor: Hussam Abu-Libdeh. Cornell University (based on slides by Saikat Guha) Fall 2011, Lecture 9
The Preprocessor CS 2022: Introduction to C Instructor: Hussam Abu-Libdeh Cornell University (based on slides by Saikat Guha) Fall 2011, Lecture 9 Preprocessor Commands to the compiler Include files, shortcuts,
More informationChapter 7: Preprocessing Directives
Chapter 7: Preprocessing Directives Outline We will only cover these topics in Chapter 7, the remain ones are optional. Introduction Symbolic Constants and Macros Source File Inclusion Conditional Compilation
More informationA Fast Review of C Essentials Part II
A Fast Review of C Essentials Part II Structural Programming by Z. Cihan TAYSI Outline Macro processing Macro substitution Removing a macro definition Macros vs. functions Built-in macros Conditional compilation
More informationErrors During Compilation and Execution Background Information
Errors During Compilation and Execution Background Information Preprocessor Directives and Compilation #define - defines a macro, identified by . During compilation, all instances of
More informationC and C++ 2. Functions Preprocessor. Alan Mycroft
C and C++ 2. Functions Preprocessor Alan Mycroft University of Cambridge (heavily based on previous years notes thanks to Alastair Beresford and Andrew Moore) Michaelmas Term 2013 2014 1 / 1 Functions
More informationC: Program Structure. Department of Computer Science College of Engineering Boise State University. September 11, /13
Department of Computer Science College of Engineering Boise State University September 11, 2017 1/13 Scope Variables and functions are visible from the point they are defined until the end of the source
More information2 Compiling a C program
2 Compiling a C program This chapter describes how to compile C programs using gcc. Programs can be compiled from a single source file or from multiple source files, and may use system libraries and header
More informationModifiers. int foo(int x) { static int y=0; /* value of y is saved */ y = x + y + 7; /* across invocations of foo */ return y; }
Modifiers unsigned. For example unsigned int would have a range of [0..2 32 1] on a 32-bit int machine. const Constant or read-only. Same as final in Java. static Similar to static in Java but not the
More informationCSci 4061 Introduction to Operating Systems. Programs in C/Unix
CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationCS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco
CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level
More information#include <stdio.h> int main() { printf ("hello class\n"); return 0; }
C #include int main() printf ("hello class\n"); return 0; Working environment Linux, gcc We ll work with c9.io website, which works with ubuntu I recommend to install ubuntu too Also in tirgul
More informationP.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above
P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above
More informationControl flow and string example. C and C++ Functions. Function type-system nasties. 2. Functions Preprocessor. Alastair R. Beresford.
Control flow and string example C and C++ 2. Functions Preprocessor Alastair R. Beresford University of Cambridge Lent Term 2007 #include char s[]="university of Cambridge Computer Laboratory";
More informationG52CPP C++ Programming Lecture 6. Dr Jason Atkin
G52CPP C++ Programming Lecture 6 Dr Jason Atkin 1 Last lecture The Stack Lifetime of local variables Global variables Static local variables const (briefly) 2 Visibility is different from lifetime Just
More informationCompiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009
Compiler Theory (GCC the GNU Compiler Collection) Sandro Spina 2009 GCC Probably the most used compiler. Not only a native compiler but it can also cross-compile any program, producing executables for
More informationRule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.
Chapter 9: Rules Chapter 1:Style and Program Organization Rule 1-1: Organize programs for readability, just as you would expect an author to organize a book. Rule 1-2: Divide each module up into a public
More informationFollow us on Twitter for important news and Compiling Programs
Follow us on Twitter for important news and updates: @ACCREVandy Compiling Programs Outline Compiling process Linking libraries Common compiling op2ons Automa2ng the process Program compilation Programmers
More informationOutline. Compiling process Linking libraries Common compiling op2ons Automa2ng the process
Compiling Programs Outline Compiling process Linking libraries Common compiling op2ons Automa2ng the process Program compilation Programmers usually writes code in high- level programming languages (e.g.
More informationCMPSC 311- Introduction to Systems Programming Module: Build Processing
CMPSC 311- Introduction to Systems Programming Module: Build Processing Professor Patrick McDaniel Fall 2016 UNIX Pipes Pipes are ways of redirecting the output of one command to the input of another Make
More informationHave examined process Creating program Have developed program Written in C Source code
Preprocessing, Compiling, Assembling, and Linking Introduction In this lesson will examine Architecture of C program Introduce C preprocessor and preprocessor directives How to use preprocessor s directives
More informationC for Engineers and Scientists: An Interpretive Approach. Chapter 7: Preprocessing Directives
Chapter 7: Preprocessing Directives Introduction Preprocessing Affect program preprocessing and execution Capabilities Inclusion of additional C source files Definition of symbolic constants and macros
More informationGabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming
1 2 CMPE 013/L Pre Processor Commands Gabriel Hugh Elkaim Spring 2013 3 Introduction Preprocessing Affect program preprocessing and execution Capabilities Inclusion of additional C source files Definition
More informationCSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 8 C: Miscellanea Control, Declarations, Preprocessor, printf/scanf 1 The story so far The low-level execution model of a process (one
More informationUnit 4 Preprocessor Directives
1 What is pre-processor? The job of C preprocessor is to process the source code before it is passed to the compiler. Source Code (test.c) Pre-Processor Intermediate Code (test.i) Compiler The pre-processor
More informationCMPSC 311- Introduction to Systems Programming Module: Build Processing
CMPSC 311- Introduction to Systems Programming Module: Build Processing Professor Patrick McDaniel Fall 2014 UNIX Pipes Pipes are ways of redirecting the output of one command to the input of another Make
More informationTopic 6: A Quick Intro To C
Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions
More informationExecutables and Linking. CS449 Spring 2016
Executables and Linking CS449 Spring 2016 Remember External Linkage Scope? #include int global = 0; void foo(); int main() { foo(); printf( global=%d\n, global); return 0; } extern int
More informationTopic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History
Topic 6: A Quick Intro To C Reading Assumption: All of you know basic Java. Much of C syntax is the same. Also: Some of you have used C or C++. Goal for this topic: you can write & run a simple C program
More informationCSE 333 Lecture 7 - final C details
CSE 333 Lecture 7 - final C details Steve Gribble Department of Computer Science & Engineering University of Washington Today s topics: - a few final C details header guards and other preprocessor tricks
More informationBasic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island
Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types
More informationCOMP322 - Introduction to C++ Lecture 02 - Basics of C++
COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.
More informationContents Lecture 3. C Preprocessor, Chapter 11 Declarations, Chapter 8. Jonas Skeppstedt Lecture / 44
Contents Lecture 3 C Preprocessor, Chapter 11 Declarations, Chapter 8 Jonas Skeppstedt (js@cs.lth.se) Lecture 3 2014 1 / 44 C Preprocessor Predefined macros Macro replacement Conditional inclusion Source
More informationFormal Methods for C
Formal Methods for C Seminar Summer Semester 2014 Daniel Dietsch, Sergio Feo Arenis, Marius Greitschus, Bernd Westphal 2014-04 main Content Brief history Comments Declarations and Scopes Variables Expressions
More informationExecutables and Linking. CS449 Fall 2017
Executables and Linking CS449 Fall 2017 Remember External Linkage Scope? #include int global = 0; void foo(); int main() { } foo(); printf( global=%d\n, global); return 0; extern int
More informationLectures 5-6: Introduction to C
Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most
More informationMacros and Preprocessor. CGS 3460, Lecture 39 Apr 17, 2006 Hen-I Yang
Macros and Preprocessor CGS 3460, Lecture 39 Apr 17, 2006 Hen-I Yang Previously Operations on Linked list (Create and Insert) Agenda Linked List (More insert, lookup and delete) Preprocessor Linked List
More informationINDEX. Figure I-0. Listing I-0. Table I-0. Symbols.DIRECTIVE (see Assembler directives)? preprocessor operator 3-34
I INDEX Figure I-0. Listing I-0. Table I-0. Symbols.DIRECTIVE (see Assembler directives)? preprocessor operator 3-34 Numerics Assembler command-line switch -21 2-21 A Address alignment 2-39 Address of
More informationCS240: Programming in C
CS240: Programming in C Lecture 6: Recursive Functions. C Pre-processor. Cristina Nita-Rotaru Lecture 6/ Fall 2013 1 Functions: extern and static Functions can be used before they are declared static for
More informationSISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:
SISTEMI EMBEDDED The C Pre-processor Fixed-size integer types Bit Manipulation Federico Baronti Last version: 20160302 The C PreProcessor CPP (1) CPP is a program called by the compiler that processes
More information0x0d2C May your signals all trap May your references be bounded All memory aligned Floats to ints round. remember...
Types Page 1 "ode to C" Monday, September 18, 2006 4:09 PM 0x0d2C ------ May your signals all trap May your references be bounded All memory aligned Floats to ints round remember... Non -zero is true ++
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationPRINCIPLES OF OPERATING SYSTEMS
PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)
More informationProgramming. Projects with Multiple Files
Programming Projects with Multiple Files Summary } GCC } Multiple source files 2 Source Code with Multiple Files } Make multiple, separate source code files which can be combined into one executable }
More informationOBJECT ORIENTED PROGRAMMING USING C++
OBJECT ORIENTED PROGRAMMING USING C++ Chapter 17 - The Preprocessor Outline 17.1 Introduction 17.2 The #include Preprocessor Directive 17.3 The #define Preprocessor Directive: Symbolic Constants 17.4 The
More informationOregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 2. Spring 2016
Oregon State University School of Electrical Engineering and Computer Science CS 261 Recitation 2 Spring 2016 Outline Programming in C o Headers o Structures o Preprocessor o Pointers Programming Assignment
More informationCS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their
More informationThe C Preprocessor (and more)!
The C Preprocessor (and more)! Peter Kristensen 2012-11-19 Peter Kristensen The C Preprocessor (and more)! Outline 1 C Pre Processor Compiler Assembler Linker Frontend 2 Simple directives Headers Macros
More informationSlide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary
Slide Set 5 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2016 ENCM 339 Fall 2016 Slide Set 5 slide 2/32
More informationCome and join us at WebLyceum
Come and join us at WebLyceum For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc Go to http://www.weblyceum.com and click Register In Case of any Problem Contact Administrators Rana Muhammad
More informationAppendix A. The Preprocessor
Appendix A The Preprocessor The preprocessor is that part of the compiler that performs various text manipulations on your program prior to the actual translation of your source code into object code.
More informationMacros in C/C++ Computer Science and Engineering College of Engineering The Ohio State University. Lecture 33
Macros in C/C++ Computer Science and Engineering College of Engineering The Ohio State University Lecture 33 Macro Definition Directive: #define #define Example: #define BUFF_SIZE 1000 A
More informationLecture 2: C Programming Basic
ECE342 Introduction to Embedded Systems Lecture 2: C Programming Basic Ying Tang Electrical and Computer Engineering Rowan University 1 Facts about C C was developed in 1972 in order to write the UNIX
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations
More informationLecture 2: C Programm
0 3 E CS 1 Lecture 2: C Programm ing C Programming Procedural thought process No built in object abstractions data separate from methods/functions Low memory overhead compared to Java No overhead of classes
More informationSISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:
SISTEMI EMBEDDED The C Pre-processor Fixed-size integer types Bit Manipulation Federico Baronti Last version: 20170307 The C PreProcessor CPP (1) CPP is a program called by the compiler that processes
More informationBasic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island
Basic C Programming Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Announcements Exam 1 (20%): Feb. 27 (Tuesday) Tentative Proposal Deadline:
More informationLecture 03 Bits, Bytes and Data Types
Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics
More informationThe C Preprocessor Compiling and Linking Using MAKE
All slides c Brandon Runnels, 2014 This presentation is not for general distribution; please do not duplicate without the author s permission. Under no circumstances should these slides be sold or used
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 STEPS OF GCC STEPS file.c Preprocessor Compiler file1.o file2.o Assembler Linker executable file PREPROCESSOR PREPROCESSOR The C preprocessor is a macro processor that is
More informationDeep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems
Deep C Multifile projects Getting it running Data types Typecasting Memory management Pointers Fabián E. Bustamante, Fall 2004 Multifile Projects Give your project a structure Modularized design Reuse
More informationFinal CSE 131B Spring 2004
Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)
More informationLecture 10: Potpourri: Enum / struct / union Advanced Unix #include function pointers
....... \ \ \ / / / / \ \ \ \ / \ / \ \ \ V /,----' / ^ \ \.--..--. / ^ \ `--- ----` / ^ \. ` > < / /_\ \. ` / /_\ \ / /_\ \ `--' \ /. \ `----. / \ \ '--' '--' / \ / \ \ / \ / / \ \ (_ ) \ (_ ) / / \ \
More informationChapter 11 Introduction to Programming in C
C: A High-Level Language Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University Gives
More informationReviewing gcc, make, gdb, and Linux Editors 1
Reviewing gcc, make, gdb, and Linux Editors 1 Colin Gordon csgordon@cs.washington.edu University of Washington CSE333 Section 1, 3/31/11 1 Lots of material borrowed from 351/303 slides Colin Gordon (University
More informationSISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:
SISTEMI EMBEDDED The C Pre-processor Fixed-size integer types Bit Manipulation Federico Baronti Last version: 20180312 The C PreProcessor CPP (1) CPP is a program called by the compiler that processes
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationConditional Compilation
Conditional Compilation printf() statements cab be inserted code for the purpose of displaying debug information during program testing. Once the program is debugged and accepted as "working'', it is desirable
More informationC Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006
C Compilation Model Comp-206 : Introduction to Software Systems Lecture 9 Alexandre Denault Computer Science McGill University Fall 2006 Midterm Date: Thursday, October 19th, 2006 Time: from 16h00 to 17h30
More informationC Preprocessor. Prabhat Kumar Padhy
C Preprocessor Prabhat Kumar Padhy 1 C Preprocessor? Creating C program, Compiling and Runnings. Create using some editor Compilation gcc test.c (or) gcc o test test.c Running./test C Preprocessor The
More informationCS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor
CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static
More informationC Programming. The C Preprocessor and Some Advanced Topics. Learn More about #define. Define a macro name Create function-like macros.
C Programming The C Preprocessor and Some Advanced Topics June 03, 2005 Learn More about #define Define a macro name Create function-like macros to avoid the time might be longer #define SUM(i, j) i+j
More informationLecture 3: C Programm
0 3 E CS 1 Lecture 3: C Programm ing Reading Quiz Note the intimidating red border! 2 A variable is: A. an area in memory that is reserved at run time to hold a value of particular type B. an area in memory
More informationCSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 C: Linked list, casts, the rest of the preprocessor (Thanks to Hal Perkins)
CSE 374 Programming Concepts & Tools Brandon Myers Winter 2015 C: Linked list, casts, the rest of the preprocessor (Thanks to Hal Perkins) Linked lists, trees, and friends Very, very common data structures
More informationQUIZ. What are 3 differences between C and C++ const variables?
QUIZ What are 3 differences between C and C++ const variables? Solution QUIZ Source: http://stackoverflow.com/questions/17349387/scope-of-macros-in-c Solution The C/C++ preprocessor substitutes mechanically,
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations
More informationindependent compilation and Make
independent compilation and Make Geoffrey Brown David S. Wise Chris Haynes Bryce Himebaugh Computer Structures Fall 2013 Independent Compilation As a matter of style, source code files should rarely be
More informationCS2141 Software Development using C/C++ Compiling a C++ Program
CS2141 Software Development using C/C++ Compiling a C++ Program g++ g++ is the GNU C++ compiler. A program in a file called hello.cpp: #include using namespace std; int main( ) { cout
More informationAppendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.
A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators
More informationPrograms. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems
Programs CSCI 4061 Introduction to Operating Systems C Program Structure Libraries and header files Compiling and building programs Executing and debugging Instructor: Abhishek Chandra Assume familiarity
More informationCOMsW Introduction to Computer Programming in C
OMsW 1003-1 Introduction to omputer Programming in Lecture 9 Spring 2011 Instructor: Michele Merler http://www1.cs.columbia.edu/~mmerler/comsw1003-1.html 1 Are omputers Smarter than Humans? Link http://latimesblogs.latimes.com/technology/2011/02/ibms-watson-on-jeopardy-computer-takes-big-leadover-humans-in-round-2.html
More information211: Computer Architecture Summer 2016
211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Structure: - header files - global / local variables - main() - macro Basic Units: - basic data types - arithmetic / logical / bit operators
More informationProgramming for Engineers C Preprocessor
Programming for Engineers C Preprocessor ICEN 200 Spring 2018 Prof. Dola Saha 1 C Preprocessor The C preprocessor executes before a program is compiled. Some actions it performs are the inclusion of other
More informationCS3157: Advanced Programming. Outline
CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch
More informationCSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 13 C: The Rest of the Preprocessor 1 Administrivia Midterm exam Wednesday, here Topics: everything up to hw4 (including gdb concepts,
More information#include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0;
1. Short answer questions: (a) Compare the typical contents of a module s header file to the contents of a module s implementation file. Which of these files defines the interface between a module and
More informationA Fast Review of C Essentials Part I
A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types
More informationMultiple file project management & Makefile
Multiple file project management & Makefile Compilation & linkage read.c read.h main.c Compilation: gcc -c read.c main.c list.c list.h list.c read.o main.o list.o Linkage: gcc... read.o main.o list.o -o
More information[Software Development] Makefiles. Davide Balzarotti. Eurecom Sophia Antipolis, France
[Software Development] Makefiles Davide Balzarotti Eurecom Sophia Antipolis, France 1 Software Development Tools 1. Configuring and Building the program GCC Makefiles Autotools 2. Writing and managing
More informationIntroduction to Supercomputing
Introduction to Supercomputing TMA4280 Introduction to UNIX environment and tools 0.1 Getting started with the environment and the bash shell interpreter Desktop computers are usually operated from a graphical
More informationDesign and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso
Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Why C? Test on 21 Android Devices with 32-bits and 64-bits processors and different versions
More informationCSCI 171 Chapter Outlines
Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures
More information1 You seek performance 3
Why? 2 1 You seek performance 3 1 You seek performance zero-overhead principle 4 2 You seek to interface directly with hardware 5 3 That s kinda it 6 C a nice way to avoid writing assembly language directly
More informationProgram Translation. text. text. binary. binary. C program (p1.c) Compiler (gcc -S) Asm code (p1.s) Assembler (gcc or as) Object code (p1.
Program Translation Compilation & Linking 1 text C program (p1.c) Compiler (gcc -S) text Asm code (p1.s) binary binary Assembler (gcc or as) Object code (p1.o) Linker (gccor ld) Executable program (p)
More informationThe Make Utility. Independent compilation. Large programs are difficult to maintain. Problem solved by breaking the program into separate files
The Make Utility Independent compilation Large programs are difficult to maintain Problem solved by breaking the program into separate files Different functions placed in different files The main function
More informationThe Make Utility. Independent compilation. Large programs are difficult to maintain. Problem solved by breaking the program into separate files
The Make Utility Independent compilation Large programs are difficult to maintain Problem solved by breaking the program into separate files Different functions placed in different files The main function
More informationCompiler, Assembler, and Linker
Compiler, Assembler, and Linker Minsoo Ryu Department of Computer Science and Engineering Hanyang University msryu@hanyang.ac.kr What is a Compilation? Preprocessor Compiler Assembler Linker Loader Contents
More informationConduite de Projet Cours 4 The C build process
Conduite de Projet Cours 4 The C build process Stefano Zacchiroli zack@pps.univ-paris-diderot.fr Laboratoire IRIF, Université Paris Diderot 2016 2017 URL http://upsilon.cc/zack/teaching/1617/cproj/ Copyright
More information