C/C++ Programming Environment

Slides:



Advertisements
Similar presentations
CSE 105 Structured Programming Language (C)
Advertisements

Chapt.2 Machine Architecture Impact of languages –Support – faster, more secure Primitive Operations –e.g. nested subroutine calls »Subroutines implemented.
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Module 6: Introduction to C Language ITEI102 Introduction to Programming Structure of C++ Program - Programming Terminologies - Microsoft Visual Studio.
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
The Environment of a UNIX Process. Introduction How is main() called? How are arguments passed? Memory layout? Memory allocation? Environment variables.
COSC 120 Computer Programming
Introduction to C Programming CE Lecture 1 Introduction to C.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Guide To UNIX Using Linux Third Edition
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Chapter 2 Software Tools and Assembly Language Syntax.
Computer Science 210 Computer Organization Introduction to C.
Chapter Introduction to Computers and Programming 1.
Introduction COMP104: Fundamentals and Methodology.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
System Calls 1.
CSC300 Visual Programming Dr. Craig Reinhart. Objectives Teach the basics of C++ –You won’t be an expert but hopefully a very good novice –GUI development.
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
Programming With C.
Engineering Computing I Chapter 1 – Part A A Tutorial Introduction.
Introduction to Computer Programming in c
Lecture 11 Dynamic link libraries. Differences between static libraries and DLLs In static library code is added to the executable. In DLL, the code is.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Topic 2d High-Level languages and Systems Software
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
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.
LANGUAGE SYSTEMS Chapter Four Modern Programming Languages 1.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
Typical C++ Environment and Library Introduction Speaker : Wei-Lu Lin Advisor : Ku-Yaw Chang 2012/10/14.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
Week 4 - Friday.  What did we talk about last time?  Some extra systems programming stuff  Scope.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
Language Translation Compilation vs. interpretation Compilation diagram Step 1: compile Step 2: run program Compiled program compiler input output Compiled.
Chapter 1: Introduction to Computers and Programming.
Operating Systems A Biswas, Dept. of Information Technology.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Chapter 1: Introduction to Computers and Programming
Lecture 3 Translation.
Topic 2: Hardware and Software
BASIC PROGRAMMING C SCP1103 (02)
Computer Terms Review from what language did C++ originate?
Tools of the Trade
A bit of C programming Lecture 3 Uli Raich.
BASIC PROGRAMMING C SCP1103 (02)
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.
Objectives Identify the built-in data types in C++
Linking & Loading.
Computer Engineering 1nd Semester
Programming COMP104: Fundamentals and Methodology Introduction.
Assembler, Compiler, Interpreter
Computer Science 210 Computer Organization
Linking & Loading CS-502 Operating Systems
Assembler, Compiler, Interpreter
Introduction to Computer Systems
Appendix F C Programming Environment on UNIX Systems
PROGRAM AT RUNTIME Subject code: CSCI-620
Linking & Loading CS-502 Operating Systems
SPL – PS1 Introduction to C++.
Presentation transcript:

C/C++ Programming Environment Few Basics Sanjaya Karunasena sanjayak@cse.mrt.ac.lk sanjaya@Virtusa.com

Outline What is a Computer Program? How to create a Computer Program using C/C++ Execution of a Computer Program Control flow

A Computer Program What is a Program? What is a Computer Program? A program is a planned sequence and combination of activities designed to achieve specified goals. [http://www.sil.org/lingualinks/literacy/ReferenceMaterials/glossaryofliteracyterms/WhatIsAProgram.htm] What is a Computer Program? A set of instructions that direct a computer to carry out a given task. [http://www.its.ex.ac.uk/glossary.shtml]

A Computer Program cont. In a typical computer (Von Neumann Architecture) A program resides in some permanent storage (Disk – File System, ROM, NVRAM, etc) When it is executed, it gets loaded in to the memory (RAM) Then instructions are fetched in to the CPU and executed

Program Creation A Programming Language can be used To write a Program, any Text Editor can be used But an Integrated Development Environment (IDE) makes our life easier Following file extensions typically belongs to C/C++ code files Source Files Header Files *.c *.h *.cc *.chh *.cpp *.hpp *.c++ *.h++ *.cxx *.hxx

Program Creation cont. A compiler should be used compile the code written gcc, cc, g++, c++ : Some Unix C/C++ compilers cl.exe : Compiler Linker comes with Microsoft Visual Studio The compiler produces Common Object File Format (COFF – UNIX and Windows systems) or Executable and Linkable Format (ELF – Most UNIX systems) files called Object Files or Object Code *.o in UNIX *.obj in Windows

Program Creation cont. *.h Files *.h Files Pre-Processor Compiler Object File *.cpp File *.cpp File Linker Static Library Object File Executable Note: A Static Library is a collection of object files

Program Creation cont. A Linker should be used to link the Object Files with other Object Files and Libraries ld in UNIX link.exe, comes with Microsoft Visual Studio The Linker produces the executable file(s) or libraries *.exe, *.lib, *.dll in Windows a.out default but can be given any name, *.bin, *.a, *.so in UNIX An interpreted program is executed using an Interpreter (No need to compile) VB, JavaScript, PERL, TCL

Program Execution Machine Program In Memory Load into Memory Dynamic Library Executable Note: Kernel API has functions (CreateProcess, fork) which can be used to load and execute a program

IDE, Compiler and Linker IDEs, Compilers and Linkers are also Programs How did the first Compiler / Linker created? This is not a Chicken and Egg problem

The Main Function The main function of a C/C++ program could be of couple of forms In C int main (void) In C++ int main ( ) In C/C++ int main (int argc, char ** argv) In Windows GUI Applications int WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) When a program is executed the C/C++ run time environment calls this function

The Main Function cont. You cannot call main from within a program or take the address of main You cannot overload this function This is the programmer’s entry point to a program What is the system entry point to a program?

C Run-Time Startup C Run-Time Startup could be of many forms depend on the type of the application Function name Default for mainCRTStartup (or wmainCRTStartup) An application using /SUBSYSTEM:CONSOLE; calls main (or wmain) WinMainCRTStartup (or wWinMainCRTStartup) An application using /SUBSYSTEM:WINDOWS; calls WinMain (or wWinMain), which must be defined with __stdcall _DllMainCRTStartup A DLL; calls DllMain, which must be defined with __stdcall, if it exists

C Run-Time Startup cont. The C/C++ compiler implements system entry point, mainCRTStartup function for us By default the linker appoint mainCRTStartup function as the system entry point to a program (A different function can be given with the linker option “/ENTRY:function”) Hence the system calls mainCRTStartup The mainCRTStartup calls our main function

Actual Execution Flow main mainCRTStartup KERNEL EXECUTABLE Initialize Get Environment Variables Call to main Clean up Your Program Code main mainCRTStartup KERNEL EXECUTABLE

void main() The ISO C++ Standard (ISO/IEC 14882:1998) specifically requires main to return int But the ISO C Standard (ISO/IEC 9899:1999) actually does not If the return type is not compatible with int, the termination status returned to the host environment is unspecified This sounds dangerous However most of the compilers takes cares of this problem for us It’s either return 0 by default or won’t allow you to implement a main function without a return type

Summary A program is a set of instructions that directs a computer to carry out a given task A programming language can be used to create a program IDE, compiler, and linker plays an important role In a C/C++ program, Programmer’s entry point is the main function By default system entry point to a C/C++ program is “mainCRTStartup”

For next couple of weeks… We need to quickly come up to the speed with basic C/C++ programming We are going to learn some thing very interesting, Object Orientation! Next week -> Introduction to Pointers Following is good tutorial http://www.cprogramming.com/tutorial/lesson1.html

For next couple of weeks… Please follow the following sections in order Intro to C++ The basics of C++ If statements If statements, and some boolean information Loops in C++ All you want to know about loops Functions Functions...all about them, making and using the critters Switch case About the switch case structure Pointers Using pointers to access memory locations Structures Structures, all about 'em, and how to use 'em Arrays All about arrays Strings About character arrays (strings) File I/O About file i/o Typecasting Typecasting: making variables look like another data-type Command line arguments How to accept command line arguments (AND checking file existence) Recursion Recursion--a function calling itself Formatted Output in C++ using iomanip Learn how to create nicely formatted output in C++ Understanding the C Preprocessor -- Constants, Macros, and other Tricks Learn how to use the C preprocessor

References http://www.delorie.com/djgpp/v2faq/faq22_25.html http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=/com.ibm.vacpp6m.doc/language/ref/clrc07mainf.htm http://homepages.tesco.net/J.deBoynePollard/FGA/legality-of-void-main.html http://msdn2.microsoft.com/en-US/library/f9t8842e(VS.80).aspx http://www.linuxjournal.com/article/6463 http://msdn.microsoft.com/visualc/ http://en.wikipedia.org