The C Programming Language

Similar documents
EL2310 Scientific Programming

EL2310 Scientific Programming

Programming in C. What is C?... What is C?

Programming in C UVic SEng 265

Programming in C. What is C?... What is C?

Spring 2018 NENG 202 Introduction to Computer Programming

CptS 360 (System Programming) Unit 2: Introduction to UNIX and Linux

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

DOWNLOAD OR READ : PROGRAMMING IN C AND INTRODUCTION TO DATA STRUCTURES AS PER VTU SYLLABUS PDF EBOOK EPUB MOBI

CSE 303 Lecture 8. Intro to C programming

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

Introduction to Cygwin Operating Environment

Software Project. Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva

Programming Languages: Part 1. Robert M. Dondero, Ph.D. Princeton University

PROGRAMMAZIONE I A.A. 2017/2018

Computers and Computation. The Modern Computer. The Operating System. The Operating System

C03c: Linkers and Loaders

Software Development. Integrated Software Environment

CS240: Programming in C

Chapter 2. Basics of Program Writing

Embest IDE Pro for ARM 2005

TDDB68 Concurrent Programming and Operating Systems. Lecture 2: Introduction to C programming

COSC 2P95. Introduction. Week 1. Brock University. Brock University (Week 1) Introduction 1 / 18

Programming Concepts: IDEs, Debug. Paulo Penteado. (

Why VC++ instead of Dev C++?

Arrays and Pointers. CSC209: Software Tools and Systems Programming (Winter 2019) Furkan Alaca & Paul Vrbik. University of Toronto Mississauga

Programming for Engineers: Getting Started

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

How to learn C? CSCI [4 6]730: A C Refresher or Introduction. Diving In: A Simple C Program 1-hello-word.c

CS201 - Lecture 1 The C Programming Language

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Introduction to Programming

An Introduction to Python (TEJ3M & TEJ4M)

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

CS354 gdb Tutorial Written by Chris Feilbach

Principles of computer programming. Profesor : doc. dr Marko Tanasković Assistent : doc. dr Marko Tanasković

INTRODUCTION TO THE COURSE

edunepal_info

CS 113: Introduction to

History of C Programming Language. Why Name C was given to Language? Summary of C Programming Language History. C Programming Language Timeline:

Binghamton University. CS-120 Summer Introduction to C. Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13

Programming. Introduction to the course

CSI33 Data Structures

Computer Basics 1/6/16. Computer Organization. Computer systems consist of hardware and software.

Motivation was to facilitate development of systems software, especially OS development.

CSCI 2132 Software Development. Lecture 2: Introduction to UNIX and Unix-like Operating Systems

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

COMP1917: Computing 1 1. Introduction

Introduction to JAVA Programming Language

COMP1917: Computing 1 1. Introduction

Computer Organization and Assembly Language. Lab Session 01

C-Language Tutorial. Apple Macintosh system software was formerly written in Pascal, but is now almost always written in C.

Programming Language Basics

1. Introduction. Course Web Site. COMP1917: Computing 1. Textbook. Occupational Health and Safety (OHS)

Conduite de Projet Cours 4 The C build process

C PROGRAMMING THE C PROGRAMMING THE PDF C PROGRAMMING TUTORIAL IN PDF - CURRENT AFFAIRS 2018 C (PROGRAMMING LANGUAGE) - WIKIPEDIA

Application Compatibility Guide

Motivation was to facilitate development of systems software, especially OS development.

ECM583 Special Topics in Computer Systems

CS 240 Fall 2015 Section 004. Alvin Chao, Professor

CS 1713 Introduction to Computer Programming II Ch 0 Overview - Problem solving

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Unit 1: Introduction to Programming. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

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

Programming Languages Part 1. Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University

Computer Basics 1/24/13. Computer Organization. Computer systems consist of hardware and software.

Introduction to C Programming

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

Never give in, never give in, never give in in nothing great or small, large or petty never give in except to convictions of honor and good sense

CS61C : Machine Structures

What is Java Platform?

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

CHAPTER 1 Introduction to Computers and Java

What s next. Computer Systems A Programmer s Perspective

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

Dr. Md. Humayun Kabir CSE Department, BUET

C++ Programming for Programmers

CS240: Programming in C

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

CS61C : Machine Structures

Introduction to IntelliJ

by Pearson Education, Inc. All Rights Reserved.

Multiple file project management & Makefile

Introduction to the C-Language and Programming Environment

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

OPERATING SYSTEM. Chapter 4: Threads

Introduction to Java Programming

Coding Tools. (Lectures on High-performance Computing for Economists VI) Jesús Fernández-Villaverde 1 and Pablo Guerrón 2 March 25, 2018

Crash Course into. Prof. Dr. Renato Pajarola

Chapter 1: Why Program? Computers and Programming. Why Program?

CMSC 246 Systems Programming

assembler Machine Code Object Files linker Executable File

CS Prof J.P.Morrison

Array Data Structure Manual In C Program Using

CITS2002 Systems Programming. Welcome to CITS2002 Systems Programming. Our UWA Handbook entry. 1 next CITS2002 CITS2002 schedule

Introduction to C Programming

Chapter 1: Introduction to Computers and Java

Welcome. HRSK Practical on Debugging, Zellescher Weg 12 Willers-Bau A106 Tel

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Transcription:

The C Programming Language

What is C? "High-level" programming language developed by Dennis Ritchie with Brian Kernighan Bell Labs, New Jersey, 1970s Developed in conjunction with Unix Intended to provide support and control of computer hardware "Systems programming", e.g. operating systems Reflects machine language instructions and behavior quite closely Detractors call it a "low-level" programming language, or a "high-level assembler"

Evolution 1972 first version introduced 1978 1st publication of "K&R" 1988 "ANSI C" standardizes language 1999 "C99" (ISO/IEC 9899:1999) inline functions; single-line comments new data types, variable length arrays (VLAs) 2011 "C11" (ISO/IEC 9899:2011) Uni support anonymous structs and unions alignment, bounds-checking; VLAs optional C99, C11 additions not always implemented!

C is an Imperative, Procedural Language It is not object-oriented No classes Class methods are replaced by globally visible functions well, not really globally visible, but not local to a class, either It is a starting point for object-oriented C++ It is not "functional" Most behavior would be considered side effects in a real functional language Functional style is possible, but ill-advised

C is a Compiled Language Source files are not executed directly Contrast with Basic, Javascript, other interpreted languages No intermediate form to interpret Contrast with Java ".jar", Python ".pyc" Executables are in hardware's native "machine language" Source must be recompiled for each target architecture Only the executable needs to be distributed

What is Compilation? Producing an executable program from (one or more) C source file(s) is a multi-step process Edit the source file Compile to produce an object file Link to produce an executable file Load/run the executable as often as desired On Linux systems the gcc program does the compile and link steps. Visual Studio does this on Windows; it also builds other files needed for the GUI (icons, other resources, etc.)

Consider: Making Java Programs Edit source.java Compile to byte.jar Syntax errors? Run the program Python is similar execute in JVM Load JVM into RAM DLLs

Building a C Program Edit source.c source Compile to object.o object Syntax errors? Run the program Link to make executable Execute as a process Load into RAM program stored on standard libraries

Complex C Programs Edit Edit source Edit source source.c source.c source saved.c source on Compile Compile to object Compile to object to object.o object.o object saved.o object on Syntax errors? Run the program Execute as a process Load into RAM DLLs program stored on Link all to make executable standard libraries

C Compile step Run gcc with flags: -Wall "Warn all" -std= choose version of C to accept -c "Compile only", produce object file -g "save symbol table for debugging Object file is created unless there are syntax errors Another possible flag: -S "compile to assembly " e.g. ansi, c99, c11 (default is a "gnu" variant)

Producing an object file Example gcc Wall c g mysource.c Remember, the source file's name must end with ".c" The compile step creates "mysource.o" unless there were syntax errors Repair any reported errors, starting with the first one Repeat until all syntax errors are fixed, and for as many source files as needed

Link step Run gcc again, with different flags -o executable_name -lm if needed (not always) brings in the standard math library Examples gcc o myprog mysource.o gcc o mathprog mymathsource.o -lm

Compiling and Linking together gcc can combine the compile and link steps: gcc Wall g o myprog mysource.c gcc Wall g o mathprog mymathsource.c -lm This is the common way to do it for smaller programs The intermediate.o file is deleted after linking

Execution Two-part process Load into memory Transfer control to beginning of Usually performed together Type executable-file s name, or click on a link Operating system loads and begins running the Examples./myprog./mathprog The./ part helps locate the file on

Final Remark: Some Free C Compilers gcc Gnu Compiler Collection Unix-like systems, MS-Windows w/ Unix emulator, other systems tcc Tiny C Compiler Unix-like systems, DOS/MS-Windows, others pcc Portable C Compiler Unix-like systems, DOS/MS-Windows, others Visual C++ Express MS-Windows development environment Borland Turbo C old DOS/MS-Windows compiler