Day 01 Introduction to Linux and C

Slides:



Advertisements
Similar presentations
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Advertisements

IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
C Intro.
C Programming Day 1 based upon Practical C Programming by Steve Oualline CS550 Operating Systems.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming CE Lecture 1 Introduction to C.
1 CSSE 332 Course Introduction. Roll Call and Introductions Name (nickname) Name (nickname) Hometown Hometown Local Residence Local Residence Major Major.
1 CSSE 332 Preprocessor, Array and Strings. 2 External library files libname.a or libname.so Special functionality is provided in the form of external.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Computer Systems DV1 (1DT151) Operating Systems (1DT020) Cary Laxer, Ph.D. Visiting Lecturer.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Introduction to C Topics Compilation Using the gcc Compiler
“Introduction to Programming With Java”
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Programming With C.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
PHYS 2020 Basic C An introduction to writing simple but useful programs in C In these lectures I will take you through the basics of C, but you will need.
Minimal standard C program int main(void) { return 0 ; }
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
First Compilation Rudra Dutta CSC Spring 2007, Section 001.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Introduction to GCC Department of Radio Physics and Electronics ILug-Cal Introduction to GCC Department of Radio Physics and Electronics, Calcutta University.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Day 01 Introduction to C.
Introduction to C Topics Compilation Using the gcc Compiler
CSC201: Computer Programming
A bit of C programming Lecture 3 Uli Raich.
Chapter 2 - Introduction to C Programming
Computer Programming Chapter 1: Introduction
Chapter 2, Part I Introduction to C Programming
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Linking & Loading.
Introduction to C Topics Compilation Using the gcc Compiler
CS-3013 Operating Systems C-term 2008
C programming language
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 2 - Introduction to C Programming
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
مباني كامپيوتر و برنامه سازي
Chapter 2 - Introduction to C Programming
Govt. Polytechnic,Dhangar
Chapter 2 - Introduction to C Programming
Programming Fundamentals Lecture #3 Overview of Computer Programming
Linking & Loading CS-502 Operating Systems
Your first C and C++ programs
C programming Language
Program Execution in Linux
Appendix F C Programming Environment on UNIX Systems
Chapter 2 - Introduction to C Programming
EECE.2160 ECE Application Programming
Linking & Loading CS-502 Operating Systems
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Day 01 Introduction to Linux and C

Why learn C (after Java)? Both high-level and low-level language Better control of low-level mechanisms Performance better than Java Java hides many details needed for writing OS code But,…. Memory management responsibility Explicit initialization and error detection More room for mistakes

Goals of this tutorial To introduce some basic C concepts to you so that you can read further details on your own To warn you about common mistakes made by beginners

Creating an executable During the linking stage, the header files and library functions are used. Source: http://www.eng.hawaii.edu/Tutor/Make/1-2.html

Types of files C source files (.c) C header files (.h) Object files (.o) Executable files (typically no extension – by default : a.out) Library files (.a or .so) *.a files are mostly static libraries *.so files are mostly dynamic libraries linking to static libraries includes the actual code for the library functions/procedures with the executable and its size will be large when compared to an executable which uses dynamic libraries.

External library files libname.a or libname.so Special functionality is provided in the form of external libraries of ready-made functions Ready-compiled code that the compiler merges, or links, with a C program during compilation For example, libraries of mathematical functions, string handling functions, and input/output functions Look for the library files under /usr/lib and header files under /usr/include .a – static library files. The object code is added to the object files at the linking stage. .so – shared library files that are dynamically linked. Two step process: 1. During linking create a symbol table that will have an entry for every reference in the library file. Blank addresses against each entry. 2. At loadtime/runtime, when the required library file is loaded into memory, then fill in the addresses in the symbol table. This is slightly slower but allows sharing of the library file by two more programs and results in smaller executables.

Example 1 – What is the output of this program? #include <stdio.h> //#include “myheader.h” int main() { printf(“Hello World. \n \t and you ! \n ”); /* print out a message */ return 0; }

Summarizing the Example #include <stdio.h> = include header file stdio.h No semicolon at end Small letters only – C is case-sensitive int main(){ … } is the only code executed printf(“ /* message you want printed */ ”); \n = newline \t = tab \ in front of other special characters within printf creates “escape sequences”. printf(“Have you heard of \”The Rock\” ? \n”); \t – tab \b – backspace \\ - slash \” – quotes Section 2.3 of K&R has the entire list as does the printf man page.

Compiling and running from the command line in UNIX/Linux prompt>gcc eg1.c (Creates a.out) prompt>./a.out (Runs the executable) prompt>gcc eg1.c –o eg1 (Creates eg1 not a.out) prompt>./eg1

To compile, use flag “l” and name i.e. –lname. Eg. gcc –o test test.c –lm where “m” in “lm” comes from libm.so i.e. the math library.

Linux and C Introduction Login to Angel Point your browser to “Course Resources” Expand the “CSSE 332 Courses” link Click on the “Course Resources Page” link Click on Introduction to Linux and C Follow the tutorial If you have any questions I am there to help