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

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

These are notes for the third lecture; if statements and loops.

Operator overloading

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

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

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

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Lecture 2: C Programming Basic

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

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

VARIABLES AND TYPES CITS1001

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

printf( Please enter another number: ); scanf( %d, &num2);

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

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

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

Lecture Notes on Generic Data Structures

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C

CMSC445 Compiler design Blaheta. Project 2: Lexer. Due: 15 February 2012

Lecture Notes on Generic Data Structures

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

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

CSE 374 Programming Concepts & Tools

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

Chapter 11 Introduction to Programming in C

A Fast Review of C Essentials Part I

Bristol Institute of Technology

Time now to look at how main causes the three LaunchPad LEDs to flash in sequence.

BLM2031 Structured Programming. Zeyneb KURT

Chapter 11 Introduction to Programming in C

EL2310 Scientific Programming

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Lecture 03 Bits, Bytes and Data Types

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

Binary, Hexadecimal and Octal number system

CSE 333 Midterm Exam 7/29/13

Variables and literals

CS Programming In C

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Compiling and Running a C Program in Unix

Better variadic functions in C

Week 8: Operator overloading

Intro to C and Binary Numbers 8/27/2007

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

Chapter 11 Introduction to Programming in C

Fall 2017 CISC124 9/16/2017

Topic 6: A Quick Intro To C

Reviewing gcc, make, gdb, and Linux Editors 1

CS61C : Machine Structures

Basic Types and Formatted I/O

Chapter 11 Introduction to Programming in C

Pointers, Arrays and Parameters

CS3157: Advanced Programming. Outline

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

Debugging. ICS312 Machine-Level and Systems Programming. Henri Casanova

Lecture 4 CSE July 1992

CS 220: Introduction to Parallel Computing. Arrays. Lecture 4

General Syntax. Operators. Variables. Arithmetic. Comparison. Assignment. Boolean. Types. Syntax int i; float j = 1.35; int k = (int) j;

Code Ninjas: Introduction to Computer Science. Macomb Science Olympiad Presented by Swati Dharia Shane Storks

CSE 351. GDB Introduction

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( )

C++ for Java Programmers

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

3/13/2012. ESc101: Introduction to Computers and Programming Languages

Chapter 7 Functions. Now consider a more advanced example:

CS61C : Machine Structures

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 C: Linked list, casts, the rest of the preprocessor (Thanks to Hal Perkins)

Lectures 5-6: Introduction to C

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage:

Starting to Program in C++ (Basics & I/O)

Chapter 3 Basic Data Types. Lecture 3 1

CS 61C: Great Ideas in Computer Architecture Introduction to C

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

4. Java Project Design, Input Methods

Functions. Using Bloodshed Dev-C++ Heejin Park. Hanyang University

Lecture 10: building large projects, beginning C++, C++ and structs

CS16 Exam #1 7/17/ Minutes 100 Points total

Ch. 3: The C in C++ - Continued -

Annotation Annotation or block comments Provide high-level description and documentation of section of code More detail than simple comments

Embedded Systems - FS 2018

1007 Imperative Programming Part II

Chapter 7. Basic Types

COSC2031 Software Tools Introduction to C

Lab 4. Out: Friday, February 25th, 2005

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

Exercise Session 2 Simon Gerber

Lecture 3. More About C

CSE 303: Concepts and Tools for Software Development

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

C How to Program, 7/e by Pearson Education, Inc. All Rights Reserved.

SU 2017 May 11/16 LAB 2: Character and integer literals, number systems, character arrays manipulation, relational operator

Chapter 1 Getting Started

About this exam review

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

EL2310 Scientific Programming

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Transcription:

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 file types, which will have different associated uses. First, let s deal with the source files themselves. Traditionally, C source files end with.c Additionally, we ll eventually learn about headers, which end with.h Brock University (Week 1b) Introduction Part Deux 2 / 14

Source Files (cont) As is common for source files, in C they re just plaintext. Sources can be written to be combined with other files for a project (libraries, etc.), or one may simply be for a program itself. In a fashion similar to Java, a C source file that represents the program will contain a procedure or function called main It may be a void procedure, or a function to return an int, and may or may not receive parameters, but we ll get into both of these topics at a later date Additionally, the file may also contain: Preprocessor directives (typically at the beginning) Constant and variable declarations External variables Other procedures and functions We ll be getting to these later, but for now it s worth explicitly noting that we don t need to encapsulate everything within a class block (because ain t got no class) Brock University (Week 1b) Introduction Part Deux 3 / 14

Gnu C Compiler GCC We ll be using GCC for compiling and linking our projects Technically, gcc actually offloads many responsibilities to other programs It automatically invokes the preprocessor before compiling, and the linker afterwards, unless directed otherwise This is a topic for later, but the preprocessor is a program that takes an initial look over all source files to look for directives specifically included for it e.g. If the compiler is going to need to know about code already provided by an IO library, then #include<stdio.h> tells the preprocessor to also look in the IO header for possible functions that might be used when the compilation starts Brock University (Week 1b) Introduction Part Deux 4 / 14

Gnu C Compiler Compilation The basic procedure for compilation is very similar to what we ve already seen for Java: 1 A preprocessor looks over all of the code to see what else needs to be included, substituted, etc. 2 The compiler runs through each source file, generating object files 3 The linker connects the object files, as well as additional libraries, sets the entry point, and produces the binary executable Invoking it as gcc -c skips the linker phase; you can manually invoke the linker later. You could actually explicitly invoke the linker ld, but I d advise against it unless you have a specific reason to. Similarly, you could only invoke the preprocessor, but outside of limited testing purposes, you likely won t ever have to. Brock University (Week 1b) Introduction Part Deux 5 / 14

Gnu C Compiler A last tidbit... Like everything in command-line linux, you really should check out the man page for gcc, but it s worth at least pointing out the -Wall option, which tells it to include extra warnings. Of course, we ve already seen similar things in Java. e.g. getting better feedback on issues with generics Brock University (Week 1b) Introduction Part Deux 6 / 14

The Preprocessor The preprocessor runs simple macros to aid in the compilation process. We ll get into some neat tricks later on (when we have an actual use for them), but for now we should at least know: #include Roughly analogous to import in Java, but not quite the same thing! Think of it as being closer to actually copy&pasting code from other files into the current source file, but without literally having to have it all in that same file Good for function prototypes, and also for sharing constants and typedefs This is the starting point for using multiple source files, but can also introduce its own conflicts #define Though many will disagree, I d suggest using this sparingly for its most common use There s really no need to use macros for things as simple as constants when you could simply define a constant the right way We ll see some really important uses of this in a later lecture Brock University (Week 1b) Introduction Part Deux 7 / 14

The simplest example ever? Pretty dang close #i n c l u d e <s t d i o. h> i n t main ( i n t argc, c h a r a r g v [ ] ) { p r i n t f ( H e l l o c l a s s! ) ; } Let s try compiling and running this, and then coming back to it in juuust a moment... Brock University (Week 1b) Introduction Part Deux 8 / 14

Variables Declaration and assignment Variable declaration and assignment are pretty much identical to Java in basic usage. Of course, some of the available types are different. An unsigned char wouldn t make a lot of sense in Java, now would it? Brock University (Week 1b) Introduction Part Deux 9 / 14

What s a printf? How do I printf numbers and variables and dragons and such? We ll be covering IO later, but for now we should probably look at output and input just a smidgen. Brock University (Week 1b) Introduction Part Deux 10 / 14

Arithmetic and Relational Operations This is reeeally familiar... Java s arithmetic and relational operators are derived primarily from C. As such, expect C to behave pretty much the same as Java. This includes things like order of operations. Just to check though, we remember things like ++,, etc., right? What s going to be fun is using relational operators without explicit boolean types, but of course we don t always even use them explicitly in Java, right? Brock University (Week 1b) Introduction Part Deux 11 / 14

Additional Operators Are we familiar with these? ^ ~ << >>? Brock University (Week 1b) Introduction Part Deux 12 / 14

Other Decimal Bases If necessary, we can express integer literals in hexadecimal or octal notation, in the same way as most other languages that offer them. No explicit binary, though. Brock University (Week 1b) Introduction Part Deux 13 / 14

Final Thoughts Are there any simple examples we d like to try? Brock University (Week 1b) Introduction Part Deux 14 / 14