The C Preprocessor Compiling and Linking Using MAKE

Size: px
Start display at page:

Download "The C Preprocessor Compiling and Linking Using MAKE"

Transcription

1 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 for profit. Author s brunnels@caltech.edu B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

2 MAKE It So: Understanding the Build Process Brandon Runnels Caltech, LANL July 16, 2014 B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

3 1 The C Preprocessor 2 Compiling and Linking 3 Using MAKE B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

4 Overview The C Preprocessor is a powerful language for processing code before it is compiled If used properly, the C Preprocessor can help make powerful, lexible, easy to read code If not understood, it can be responsible for some of the most baling compile errors you'll ever see B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

5 Basics The C Preprocessor is run before and independently of compilation The result of running the preprocessor can be seen by compiling with the -E lag The C Preprocessor is not just used for C; it is also used in FORTRAN, C++, and some other languages Commands (called directives) are always proceeded by a # sign We will look at Include Deine If, elif, endif, else B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

6 #include emacs: main.c emacs: myfile.txt Now Now is is the the time time for for all all good good men men to to come come to to the the aid aid of of their their country country Blah Blah blah blah blah... blah... #include #include my_file.txt Yadda Yadda yadda yadda yadda yadda The preprocessor physically copies and pastes all of the include iles. Running gcc with the -E option runs the preprocessor only and shows you the result. Terminal > gcc gcc -E -E main.c main.c Blah Blah blah blah blah... blah... Now Now is is the the time time for for all all good good men men to to come come to to the the aid aid of of their their country country Yadda Yadda yadda yadda yadda yadda B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

7 #define emacs: main.c Terminal #define #define MYNUMBER MYNUMBER I am am MYNUMBER MYNUMBER years years old old > gcc gcc -E -E main.c main.c I am am years years old old Deines are pretty easy. It's important, however, to remember the diference between a deine which is a macro and an actual language variable. B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

8 #ifdef Include Guards emacs: myheader.h #ifndef #ifndef HEADER_DEFINED #define #define HEADER_DEFINED header header file file #endif #endif emacs: main.h #include #include myheader.h main main header header file file emacs: main.c #include myheader.h #include #include main.h int int main() main() The solution is to add include guards. This is done in basically every C/C++ program ever to be compiled. B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

9 The C Preprocessor Some other C Preprocessor goodies: FILE : Macro for the current ile name LINE : Macro for the current line number DATE and TIME : macro for date and time at compilation Functions: #deine plus(a,b) A+B B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

10 The C Preprocessor Review The C Preprocessor processes source iles before they get to the compiler Preprocessor directives are used to make code more human readable They are also used to allow lexibility in compilation options Directives are often to blame for highly cryptic compilation errors The preprocessor is almost a language itself it is not to be underestimated! B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

11 1 The C Preprocessor 2 Compiling and Linking 3 Using MAKE B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

12 Compiling and Linking Overview: we will discuss The diference between compiling and linking The build process How to include libraries B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

13 main.c gcc a.out emacs: main.c #include myfunction.h int int main() main() { myfunction(); } emacs: myfunction.h #ifndef #ifndef MYFUNCTION_INCLUDED #define #define MYFUNCTION_INCLUDED #include <stdio.h> void void myfunction(); #endif #endif// // MYFUNCTION_INCLUDED emacs: myfunction.c #include #include myfunction.h void void myfunction() { printf( Hello, world\n ); } B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

14 main.c We've taken a simple problem and made it more complicated. How do we turn these three iles into an executable? myfunction.c? a.out myfunction.h First, we need to compile the code into object iles B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

15 myfunction.c gcc -c myfunction.o myfunction.h main.c myfunction.h gcc -c main.o COMPILING LINKING myfunction.o myfunction.o gcc a.out B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

16 Terminal We compile all of the iles into object iles the same way. Finally, we link all of the object iles together. (Note that there is no -c in the line) > gcc gcc main.c main.c Undefined reference to to 'myfunction' > gcc gcc main.c main.c Undefined reference to to 'myfunction' > gcc gcc -c -c main.c main.c > gcc gcc -c -c myfunction.c > gcc gcc main.o main.o myfunction.o B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

17 Shared vs. Static Libraries: A dynamic library is not compiled into the code. It contains precompiled code that will only be made available at runtime The size of a.out is independent of the size of the shared library a.out is not a complete program. It will only run on computers that have a copy of package.so available at runtime myfunction.o main.o package.so Linking a.out B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

18 Shared vs. Static Libraries: Running Terminal Hello, Hello, world world > ldd ldd./a.out./a.out linux-vdso.so.1 (0x00007fffed4f0000) libmylib.so => =>./libmylib.so (0x00007fa82cd85000) libc.so.6 => => /usr/lib/libc.so.6 (0x00007fa82c9d8000) /lib64/ld-linux-x86-64.so.2 (0x00007fa82cf86000) > The command ldd <executable_name> lists all of the libraries on which the executable depends B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

19 Shared vs. Static Libraries: Static Libraries Portable all code is self contained Fast all routines are already in memory at runtime Easy to use does not require system reconiguration to run Dynamic Libraries Flexible dependency upgrades do not require a recompilation Small Size of the binary executable is only as large as the unique code that it contains B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

20 1 The C Preprocessor 2 Compiling and Linking 3 Using MAKE B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

21 Using MAKE Overview: we will discuss What Make does How to write a simple Makeile B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

22 emacs: Makefile Terminal > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

23 emacs: Makefile Hello,world This is a target like a function but diferent as we'll see. When the target is executed, all of the indented text is fed right into the terminal Terminal > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

24 emacs: Makefile Hello,world This is a target like a function but diferent as we'll see. When the target is executed, all of the indented text is fed right into the terminal Terminal > make make Hello, Hello, world world > make make default default Hello, Hello, world world > echo echo Hello, Hello, world world Hello Hello world world B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

25 emacs: Makefile default: default: #This #This is is a comment comment echo echo Hello,world Even comments get fed to the terminal. The # character is ignored by the shell. Adding before a command suppresses the actual command in the shell useful for echo. Terminal > make make #This #This is is a comment comment echo echo Hello, Hello, world world Hello, Hello, world world > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

26 emacs: Makefile default: default: gcc gcc -c -c myfunction.c gcc gcc -c -c main.c main.c gcc gcc main.o main.o myfunction.o Makeiles are usually used to compile code This is something that could be done with a script. However, Make is far more powerful than that... Terminal > make make gcc gcc -c -c myfunction.c gcc gcc -c -c main.c main.c gcc gcc main.o main.o myfunction.o > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

27 emacs: Makefile default: default: Compile complete! compile: gcc gcc -c -c myfunction.c gcc gcc -c -c main.c main.c gcc gcc main.o main.o myfunction.o A dependency. Before default is executed, Make looks for targets that match its dependency and executes those targets irst. Targets can be labels, variables, or ilenames. Terminal > make make gcc gcc -c -c myfunction.c gcc gcc -c -c main.c main.c gcc gcc main.o main.o myfunction.o Compile Compile complete! > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

28 emacs: Makefile default: default: Compile complete! compile: main.o main.o myfunction.o gcc gcc main.o main.o myfunction.o main.o: main.o: gcc gcc -c -c main.c main.c myfunction.o: gcc gcc -c -c myfunction.c A target can be a ilename as well. A target called ile.ext is a rule for making ile.ext Terminal > make make gcc gcc -c -c myfunction.c gcc gcc -c -c main.c main.c gcc gcc main.o main.o myfunction.o Compile Compile complete! > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

29 SRC SRC = myfunction.c main.c main.c OBJ OBJ = myfunction.o main.o main.o default: Compile complete! compile: compile: ${OBJ} ${OBJ} gcc gcc ${OBJ} ${OBJ} emacs: Makefile main.o: main.o: gcc gcc -c -c main.c main.c myfunction.o: gcc gcc -c -c myfunction.c Variables are declared directly Variables are called with ${...} (just like environment variables) Undeined variables have value Make will not complain Terminal > make make gcc gcc -c -c myfunction.c gcc gcc -c -c main.c main.c gcc gcc main.o main.o myfunction.o Compile Compile complete! > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

30 SRC SRC = myfunction.c main.c main.c OBJ OBJ = myfunction.o main.o main.o default: Compile complete! compile: compile: ${OBJ} ${OBJ} gcc gcc ${OBJ} ${OBJ} main.o: main.o: main.c main.c gcc gcc -c -c main.c main.c myfunction.o: myfunction.c gcc gcc -c -c myfunction.c main.c: main.c: myfunction.c: emacs: Makefile Targets are only executed if their dependencies are up to date Now, main.c will only compiled if it has been changed since main.o All dependencies require targets; otherwise Make will complain no rule to make target main.c Terminal > make make gcc gcc -c -c myfunction.c gcc gcc -c -c main.c main.c gcc gcc main.o main.o myfunction.o Compile Compile complete! > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

31 SRC SRC = myfunction.c main.c main.c OBJ OBJ = myfunction.o main.o main.o default: Compile complete! compile: compile: ${OBJ} ${OBJ} gcc gcc ${OBJ} ${OBJ} main.o: main.o: main.c main.c gcc gcc -c -c main.c main.c myfunction.o: myfunction.c gcc gcc -c -c myfunction.c main.c: main.c: myfunction.c: emacs: Makefile So far: we've taken a simple, scriptable sequence of commands and turned it into a mess. Fortunately, Make provides some very nifty tricks to collapse most of this. Terminal > make make gcc gcc -c -c myfunction.c gcc gcc -c -c main.c main.c gcc gcc main.o main.o myfunction.o Compile Compile complete! > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

32 SRC SRC = ${wildcard *.c} *.c} OBJ OBJ = ${SRC:.c=.o} default: Compile complete! compile: compile: ${OBJ} ${OBJ} gcc gcc ${OBJ} ${OBJ} main.o: main.o: main.c main.c gcc gcc -c -c main.c main.c myfunction.o: myfunction.c gcc gcc -c -c myfunction.c main.c: main.c: myfunction.c: emacs: Makefile So far: we've taken a simple, scriptable sequence of commands and turned it into a mess. Fortunately, Make provides some very nifty tricks to collapse most of this. Terminal > make make gcc gcc -c -c myfunction.c gcc gcc -c -c main.c main.c gcc gcc main.o main.o myfunction.o Compile Compile complete! > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

33 SRC SRC = ${wildcard *.c} *.c} OBJ OBJ = ${SRC:.c=.o} default: Compile complete! compile: compile: ${OBJ} ${OBJ} gcc gcc ${OBJ} ${OBJ} main.o: main.o: main.c main.c gcc gcc -c -c main.c main.c myfunction.o: myfunction.c gcc gcc -c -c myfunction.c %.c: %.c: emacs: Makefile So far: we've taken a simple, scriptable sequence of commands and turned it into a mess. Fortunately, Make provides some very nifty tricks to collapse most of this. Terminal > make make gcc gcc -c -c myfunction.c gcc gcc -c -c main.c main.c gcc gcc main.o main.o myfunction.o Compile Compile complete! > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

34 SRC SRC = ${wildcard *.c} *.c} OBJ OBJ = ${SRC:.c=.o} default: Compile complete! compile: compile: ${OBJ} ${OBJ} gcc gcc ${OBJ} ${OBJ} %.o: %.o:%.c %.c gcc gcc -c -c $< $< %.c: %.c: emacs: Makefile %.o: General target for any target of the form ilename.c %.c: Replaces.c with.o on ilename.c $<: The irst dependancy Terminal > make make gcc gcc -c -c myfunction.c gcc gcc -c -c main.c main.c gcc gcc main.o main.o myfunction.o Compile Compile complete! > B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

35 SRC SRC = ${wildcard *.c} *.c} OBJ OBJ = ${SRC:.c=.o} default: Compile complete! compile: compile: ${OBJ} ${OBJ} gcc gcc ${OBJ} ${OBJ} %.o: %.o:%.c %.c gcc gcc -c -c $< $< %.c: %.c: emacs: Makefile PITFALL: Make knows that your executable depends on the object iles which depend on their corresponding source iles. If you change a source ile Make knows to recompile. This does not work for header iles. Changing a header ile will not trigger Make to recompile: you must do that manually. B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

36 Using MAKE Review Make is a powerful but specialized system for managing the compilation of a complicated code Make is the de facto system for building large code packages it pays to learn it! B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

37 Thanks! B. Runnels ( Caltech, LANL ) MAKE It So 7/16/ / 37

2 Compiling a C program

2 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 information

The C standard library

The C standard library C introduction The C standard library The C standard library 1 / 12 Contents Do not reinvent the wheel Useful headers Man page The C standard library 2 / 12 The Hitchhiker s Guide to the standard library

More information

C: Program Structure. Department of Computer Science College of Engineering Boise State University. September 11, /13

C: 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 information

Topic 6: A Quick Intro To C

Topic 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 information

CS2141 Software Development using C/C++ Compiling a C++ Program

CS2141 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 information

Introduction to C An overview of the programming language C, syntax, data types and input/output

Introduction to C An overview of the programming language C, syntax, data types and input/output Introduction to C An overview of the programming language C, syntax, data types and input/output Teil I. a first C program TU Bergakademie Freiberg INMO M. Brändel 2018-10-23 1 PROGRAMMING LANGUAGE C is

More information

Intermediate Programming, Spring 2017*

Intermediate 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 information

Follow us on Twitter for important news and Compiling Programs

Follow 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 information

A Fast Review of C Essentials Part II

A 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 information

Practical C Issues:! Preprocessor Directives, Multi-file Development, Makefiles. CS449 Fall 2017

Practical C Issues:! Preprocessor Directives, Multi-file Development, Makefiles. CS449 Fall 2017 Practical C Issues:! Preprocessor Directives, Multi-file Development, Makefiles CS449 Fall 2017 Multi-file Development Multi-file Development Why break code into multiple source files? Parallel development

More information

Conditional Compilation

Conditional 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 information

make and makefile CS 211

make and makefile CS 211 make and makefile CS 211 Steps of a C Program Compilation Step 1 Run the Preprocessor Deals with #include, #define, #ifndef, Step 2 Compile C code into Machine Code Step 2a Lexical Analysis Step 2b Parsing

More information

independent compilation and Make

independent 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 information

Executables and Linking. CS449 Spring 2016

Executables 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 information

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Topic 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 information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 2: Hello World! Cristina Nita-Rotaru Lecture 2/ Fall 2013 1 Introducing C High-level programming language Developed between 1969 and 1973 by Dennis Ritchie at the Bell Labs

More information

Errors During Compilation and Execution Background Information

Errors 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 information

Compiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009

Compiler 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 information

CS 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 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

Intermediate Programming, Spring 2017*

Intermediate 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 information

Programming in C week 1 meeting Tiina Niklander

Programming in C week 1 meeting Tiina Niklander Programming in C week 1 meeting 2.9.2015 Tiina Niklander Faculty of Science Department of Computer Science 3.9.2015 1 Course structure Based on C programming course in Aalto, but with some exercises created

More information

The Compilation Process

The Compilation Process The Compilation Process Olaf Lenz http://wwwicpuni-stuttgartde Institut für Computerphysik Universität Stuttgart March 17-21, 2014 Separate Compilation http://wwwicpuni-stuttgartde So far, all programs

More information

CS Basics 15) Compiling a C prog.

CS Basics 15) Compiling a C prog. CS Basics 15) Compiling a C prog. Emmanuel Benoist Fall Term 2016-17 Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 1 Compiling a C program Example of a small

More information

Executables and Linking. CS449 Fall 2017

Executables 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 information

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2 Compiling a C program CS Basics 15) Compiling a C prog. Emmanuel Benoist Fall Term 2016-17 Example of a small program Makefile Define Variables Compilation options Conclusion Berner Fachhochschule Haute

More information

Programming in C First meeting

Programming in C First meeting Programming in C First meeting 8.9.2016 Tiina Niklander Faculty of Science Department of Computer Science www.cs.helsinki.fi 8.9.2016 1 Course structure Weekly exercise deadline on Wednesday, lectures

More information

The 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 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 information

CMPT 300. Operating Systems. Brief Intro to UNIX and C

CMPT 300. Operating Systems. Brief Intro to UNIX and C CMPT 300 Operating Systems Brief Intro to UNIX and C Outline Welcome Review Questions UNIX basics and Vi editor Using SSH to remote access Lab2(4214) Compiling a C Program Makefile Basic C/C++ programming

More information

Functions. Cedric Saule

Functions. Cedric Saule Cedric Saule cedric.saule@uni-bielefeld.de or procedures? In algorithmic (and some programming languages), we use two kinds of unconditional branchings : Procedures : execute computations and do not return

More information

Tutorial: Compiling, Makefile, Parallel jobs

Tutorial: Compiling, Makefile, Parallel jobs Tutorial: Compiling, Makefile, Parallel jobs Hartmut Häfner Steinbuch Centre for Computing (SCC) Funding: www.bwhpc-c5.de Outline Compiler + Numerical Libraries commands Linking Makefile Intro, Syntax

More information

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Programs. 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 information

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3 Hello, World! in C Johann Myrkraverk Oskarsson October 23, 2018 Contents 1 The Quintessential Example Program 1 I Printing Text 2 II The Main Function 3 III The Header Files 4 IV Compiling and Running

More information

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2 CS 220: Introduction to Parallel Computing Beginning C Lecture 2 Today s Schedule More C Background Differences: C vs Java/Python The C Compiler HW0 8/25/17 CS 220: Parallel Computing 2 Today s Schedule

More information

COSC 2P91. Bringing it all together... Week 4b. Brock University. Brock University (Week 4b) Bringing it all together... 1 / 22

COSC 2P91. Bringing it all together... Week 4b. Brock University. Brock University (Week 4b) Bringing it all together... 1 / 22 COSC 2P91 Bringing it all together... Week 4b Brock University Brock University (Week 4b) Bringing it all together... 1 / 22 A note on practicality and program design... Writing a single, monolithic source

More information

HPC User Environment

HPC User Environment HPC User Environment Dirk Schmidl schmidl@rz.rwth-aachen.de Center for Computing and Communication RWTH Aachen University 22.03.2010 1 Program development tools on Linux IDEs eclipse sunstudio kdevelop

More information

KYC - Know your compiler. Introduction to GCC

KYC - Know your compiler. Introduction to GCC KYC - Know your compiler Introduction to GCC The Operating System User User 1 General Purpose or Application Specific Software Operating System Kernel Computer Hardware User 2 What is GCC? GCC is the GNU

More information

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang Topics History of Programming Languages Compilation Process Anatomy of C CMSC 104 Coding Standards Machine Code In the beginning,

More information

CSE 351. Introduction & Course Tools

CSE 351. Introduction & Course Tools CSE 351 Introduction & Course Tools Meet Your TA TA Name Interesting information examples: Where you are from Year in school Hobbies Unique talents Introductions Pick an interesting (but quick) ice breaker

More information

Slide 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 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 information

Introduction to System Programming : makefile

Introduction to System Programming : makefile Introduction to System Programming : makefile Reference Documentation: http://www.gnu.org/software/make/manual/make.html Tutorials: http://www.cs.umd.edu/class/spring2002/cmsc214/tutorial/makefile.html

More information

GDB and Makefile. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

GDB and Makefile. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island GDB and Makefile Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island GDB Debugging: An Example #include void main() { int i; int result

More information

CSE 333 Midterm Exam 5/9/14 Sample Solution

CSE 333 Midterm Exam 5/9/14 Sample Solution Question 1. (20 points) C programming. Implement the C library function strncpy. The specification of srncpy is as follows: Copy characters (bytes) from src to dst until either a '\0' character is found

More information

Linking and Loading. ICS312 - Spring 2010 Machine-Level and Systems Programming. Henri Casanova

Linking and Loading. ICS312 - Spring 2010 Machine-Level and Systems Programming. Henri Casanova Linking and Loading ICS312 - Spring 2010 Machine-Level and Systems Programming Henri Casanova (henric@hawaii.edu) The Big Picture High-level code char *tmpfilename; int num_schedulers=0; int num_request_submitters=0;

More information

Reliable C++ development - session 1: From C to C++ (and some C++ features)

Reliable C++ development - session 1: From C to C++ (and some C++ features) Reliable C++ development - session 1: From C to C++ (and some C++ features) Thibault CHOLEZ - thibault.cholez@loria.fr TELECOM Nancy - Université de Lorraine LORIA - INRIA Nancy Grand-Est From Nicolas

More information

Chapter 7: Preprocessing Directives

Chapter 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 information

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011 Oregon State University School of Electrical Engineering and Computer Science CS 261 Recitation 1 Spring 2011 Outline Using Secure Shell Clients GCC Some Examples Intro to C * * Windows File transfer client:

More information

Chapter 11 Introduction to Programming in C

Chapter 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 information

The 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 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 information

Your first C and C++ programs

Your first C and C++ programs Your first C and C++ programs Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++,

More information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University C: A High-Level Language! Gives

More information

#include <stdio.h> int main() { printf ("hello class\n"); return 0; }

#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 information

Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance. John Edgar 2

Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance. John Edgar 2 CMPT 125 Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance John Edgar 2 Edit or write your program Using a text editor like gedit Save program with

More information

Programming in C First meeting Tiina Niklander

Programming in C First meeting Tiina Niklander Programming in C First meeting 5.9.2016 Tiina Niklander Faculty of Science Department of Computer Science www.cs.helsinki.fi 5.9.2018 1 Learning goal objectives Language structures, data structures, modules,

More information

Software Development With Emacs: The Edit-Compile-Debug Cycle

Software Development With Emacs: The Edit-Compile-Debug Cycle Software Development With Emacs: The Edit-Compile-Debug Cycle Luis Fernandes Department of Electrical and Computer Engineering Ryerson Polytechnic University August 8, 2017 The Emacs editor permits the

More information

CSCI 2132 Software Development. Lecture 8: Introduction to C

CSCI 2132 Software Development. Lecture 8: Introduction to C CSCI 2132 Software Development Lecture 8: Introduction to C Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 21-Sep-2018 (8) CSCI 2132 1 Previous Lecture Filename substitution

More information

C 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 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 information

CS240: Programming in C. Lecture 2: Overview

CS240: Programming in C. Lecture 2: Overview CS240: Programming in C Lecture 2: Overview 1 Programming Model How does C view the world? Stack Memory code Globals 2 Programming Model Execution mediated via a stack function calls and returns local

More information

Draft. Chapter 1 Program Structure. 1.1 Introduction. 1.2 The 0s and the 1s. 1.3 Bits and Bytes. 1.4 Representation of Numbers in Memory

Draft. Chapter 1 Program Structure. 1.1 Introduction. 1.2 The 0s and the 1s. 1.3 Bits and Bytes. 1.4 Representation of Numbers in Memory Chapter 1 Program Structure In the beginning there were 0s and 1s. GRR 1.1 Introduction In this chapter we will talk about memory: bits, bytes and how data is represented in the computer. We will also

More information

CSE2301. Functions. Functions and Compiler Directives

CSE2301. Functions. Functions and Compiler Directives Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who

More information

Chris' Makefile Tutorial

Chris' Makefile Tutorial Chris' Makefile Tutorial Chris Serson University of Victoria June 26, 2007 Contents: Chapter Page Introduction 2 1 The most basic of Makefiles 3 2 Syntax so far 5 3 Making Makefiles Modular 7 4 Multi-file

More information

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga C-Programming CSC209: Software Tools and Systems Programming Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Adapted from Dan Zingaro s 2015 slides. Week 2.0 1 / 19 What

More information

Course organization. Course introduction ( Week 1)

Course organization. Course introduction ( Week 1) Course organization Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 2-9) Chapter 1: Overall Introduction (Week 1-3) Chapter 2: Types, operators and

More information

SISTEMI 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: 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 information

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program. Language Translation Compilation vs. interpretation Compilation diagram Step 1: compile program compiler Compiled program Step 2: run input Compiled program output Language Translation compilation is translation

More information

More on C programming

More on C programming Applied mechatronics More on C programming Sven Gestegård Robertz sven.robertz@cs.lth.se Department of Computer Science, Lund University 2017 Outline 1 Pointers and structs 2 On number representation Hexadecimal

More information

COSC345 Software Engineering. Make

COSC345 Software Engineering. Make COSC345 Software Engineering Make The build process Make When to use make How to use make Suffix rules makedepend Outline Warning: Make is different everywhere you go! Build Process The build process can

More information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified by Chris Wilcox, Yashwant Malaiya Colorado State University C: A High-Level Language

More information

0x0d2C May your signals all trap May your references be bounded All memory aligned Floats to ints round. remember...

0x0d2C 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 information

Chapter 11 Introduction to Programming in C

Chapter 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 information

Deep 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. 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 information

Formal Methods for C

Formal 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 information

#include. Practical C Issues: #define. #define Macros. Example. #if

#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 information

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Rule 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 information

(Extract from the slides by Terrance E. Boult

(Extract from the slides by Terrance E. Boult What software engineers need to know about linking and a few things about execution (Extract from the slides by Terrance E. Boult http://vast.uccs.edu/~tboult/) A Simplistic Program Translation Scheme

More information

C - Basics, Bitwise Operator. Zhaoguo Wang

C - Basics, Bitwise Operator. Zhaoguo Wang C - Basics, Bitwise Operator Zhaoguo Wang Java is the best language!!! NO! C is the best!!!! Languages C Java Python 1972 1995 2000 (2.0) Procedure Object oriented Procedure & object oriented Compiled

More information

Make. Dependency Graphs

Make. Dependency Graphs Make Typical program development cycle think edit compile test Potential problems edit a file, but forget to compile it edit an interface, but forget to compile all the files that depend on it do more

More information

Lecture 10: Potpourri: Enum / struct / union Advanced Unix #include function pointers

Lecture 10: Potpourri: Enum / struct / union Advanced Unix #include function pointers ....... \ \ \ / / / / \ \ \ \ / \ / \ \ \ V /,----' / ^ \ \.--..--. / ^ \ `--- ----` / ^ \. ` > < / /_\ \. ` / /_\ \ / /_\ \ `--' \ /. \ `----. / \ \ '--' '--' / \ / \ \ / \ / / \ \ (_ ) \ (_ ) / / \ \

More information

GNU make... Martin Ohlerich, Parallel Programming of High Performance Systems

GNU make... Martin Ohlerich, Parallel Programming of High Performance Systems ... Martin Ohlerich, Martin.Ohlerich@lrz.de Parallel Programming of High Performance Systems Outline 1 2 3 Leibniz Rechenzentrum 2 / 42 Outline 1 2 3 Leibniz Rechenzentrum 3 / 42 Common Situation Larger

More information

Portable C Code

Portable C Code Chapter 6: Implementing Fuzzy Runtime Systems 6.1.4. Portable C Code The source codes generated by the fuzzytech C code generator are portable. Thus, fuzzy runtime systems can be implemented on any target

More information

Modifiers. int foo(int x) { static int y=0; /* value of y is saved */ y = x + y + 7; /* across invocations of foo */ return y; }

Modifiers. 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 information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 7: Introduction to C (pronobis@kth.se) Overview Overview Lecture 7: Introduction to C Wrap Up Basic Datatypes and printf Branching and Loops in C Constant values Wrap Up Lecture 7: Introduction

More information

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p.

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p. Lecture 10 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 10: Formatted Input and Output 27-Sep-2017 Location: Goldberg CS 127 Time: 14:35 15:25 Instructor:

More information

SISTEMI 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: 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 information

Compiler Drivers = GCC

Compiler Drivers = GCC Compiler Drivers = GCC When you invoke GCC, it normally does preprocessing, compilation, assembly and linking, as needed, on behalf of the user accepts options and file names as operands % gcc O1 -g -o

More information

We d like to hear your suggestions for improving our indexes. Send to

We d like to hear your suggestions for improving our indexes. Send  to Index [ ] (brackets) wildcard, 12 { } (curly braces) in variables, 41 ( ) (parentheses) in variables, 41 += (append) operator, 45 * (asterisk) wildcard, 12 $% automatic variable, 16 $+ automatic variable,

More information

INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE

INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE HEADER FILE A header (.h,.hpp,...) file contains Class definitions ( class X {... }; ) Inline function definitions ( inline int get_x() {... } ) Function declarations ( void help(); ) Object declarations

More information

[Software Development] Makefiles. Davide Balzarotti. Eurecom Sophia Antipolis, France

[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 information

C and C++ I. Spring 2014 Carola Wenk

C and C++ I. Spring 2014 Carola Wenk C and C++ I Spring 2014 Carola Wenk Different Languages Python sum = 0 i = 1 while (i

More information

COSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14

COSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14 COSC 2P91 Introduction Part Deux Week 1b Brock University Brock University (Week 1b) Introduction Part Deux 1 / 14 Source Files Like most other compiled languages, we ll be dealing with a few different

More information

CSCI-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 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 information

C and C++ 2. Functions Preprocessor. Alan Mycroft

C 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 information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1 BIL 104E Introduction to Scientific and Engineering Computing Lecture 1 Introduction As engineers and scientists why do we need computers? We use computers to solve a variety of problems ranging from evaluation

More information

Workshop Agenda Feb 25 th 2015

Workshop Agenda Feb 25 th 2015 Workshop Agenda Feb 25 th 2015 Time Presenter Title 09:30 T. König Talk bwhpc Concept & bwhpc-c5 - Federated User Support Activities 09:45 R. Walter Talk bwhpc architecture (bwunicluster, bwforcluster

More information

SISTEMI 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: 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 information

Exercise 1: Basic Tools

Exercise 1: Basic Tools Exercise 1: Basic Tools This exercise is created so everybody can learn the basic tools we will use during this course. It is really more like a tutorial than an exercise and, you are not required to submit

More information

Course organization. Part I: Introduction to C programming language (Week 1-12) Chapter 1: Overall Introduction (Week 1-4)

Course organization. Part I: Introduction to C programming language (Week 1-12) Chapter 1: Overall Introduction (Week 1-4) Course organization 1 Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 1-12) Chapter 1: Overall Introduction (Week 1-4) C Unix/Linux Chapter 2: Types,

More information

Design 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 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 information

Using the EE 109 Tools. Allan Weber Mark Redekopp

Using the EE 109 Tools. Allan Weber Mark Redekopp 1 Using the EE 109 Tools Allan Weber Mark Redekopp 2 Note and Disclaimer Please follow the instructions at http://ee-classes.usc.edu/ee109/project_tips.html to setup new labs/projects for your Arduino

More information

Chapter 11 Introduction to Programming in C

Chapter 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 information

Have examined process Creating program Have developed program Written in C Source code

Have 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 information