ENERGY 211 / CME 211 Lecture 29 December 3, 2008.

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Chapter 7: User-Defined Functions II
The Environment of a UNIX Process. Introduction How is main() called? How are arguments passed? Memory layout? Memory allocation? Environment variables.
Unix Process Environment. main Function A C program starts execution with a function called main. The prototype for the main function is: int main (int.
Guide To UNIX Using Linux Third Edition
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
University of Calgary – CPSC 441. C PROGRAM  Collection of functions  One function “main()” is called by the operating system as the starting function.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
Runtime Environments Compiler Construction Chapter 7.
Basic Semantics Associating meaning with language entities.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Command Line Arguments.
Lecture 3: Getting Started & Input / Output (I/O) “TRON” Copyright 1982 (Walt Disney Productions)
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Unit 10 Code Reuse. Key Concepts Abstraction Header files Implementation files Storage classes Exit function Conditional compilation Command-line arguments.
Defining Your Own Classes II
Lecture 3: Getting Started & Input / Output (I/O)
Lecture 3 Translation.
Pointers and Classes.
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
ECE Application Programming
User-Written Functions
APPENDIX a WRITING SUBROUTINES IN C
A bit of C programming Lecture 3 Uli Raich.
Friend Class Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful.
Characters and Strings
CISC105 – General Computer Science
Command Line Arguments
Command line arguments
Agenda Make Utility Command Line Arguments in Unix
Command Line Arguments
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
CSE 351 Section 1: HW 0 + Intro to C
Checking Memory Management
Command-Line Arguments
Programmazione I a.a. 2017/2018.
Instructor: Ioannis A. Vetsikas
CSCE 210 Data Structures and Algorithms
Pointers and References
TCL command in C, a simple example Nguyen Truong – GCS VN Aug 5, 2004
C-Programming, continued
CSC 253 Lecture 8.
Command Line Parameters
CSC 253 Lecture 8.
C Stuff CS 2308.
7 Arrays.
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
From C++ to Java Java history: Oak, toaster-ovens, internet language, panacea What it is O-O language, not a hybrid (cf. C++) compiled to byte-code, executed.
Strings and Pointer Arrays
7 Arrays.
ECE 103 Engineering Programming Chapter 46 argc, argv, envp
Submitted By : Veenu Saini Lecturer (IT)
Chapter 9: Pointers and String
Chapter 9: Pointers and String
Summary CSE 2031 Fall May 2019.
Data Structures and ADTs
Functions Reasons Concepts Passing arguments to a function
ENERGY 211 / CME 211 Lecture 8 October 8, 2008.
ENERGY 211 / CME 211 Lecture 30 December 5, 2008.
Quick Review EECS May 2019.
Characters and Strings
ENERGY 211 / CME 211 Lecture 10 October 13, 2008.
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
ENERGY 211 / CME 211 Lecture 28 December 1, 2008.
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
SPL – PS1 Introduction to C++.
Presentation transcript:

ENERGY 211 / CME 211 Lecture 29 December 3, 2008

Command-line Arguments main actually accepts arguments: int argc: number of command-line arguments char *argv[]: array of argc C strings containing the arguments First argument, argv[0], is name of the executable Arguments separated by spaces Typically, arguments used to customize execution

Calling FORTRAN from C++ Add _ to name of FORTRAN function Pass addresses of non-array arguments Remember that matrices are stored in column order in FORTRAN, so be sure to keep code consistent FORTRAN functions must be declared like other external functions Precede declaration with extern "C" so simple C naming convention used

Linking FORTRAN with C++ Use gfortran –c to compile each FORTRAN source file On elaine or other workstations, can also use f90, but that is not a GNU compiler and doesn't always work with C++ code compiled with g++ Use g++ -c to compile each C++ source file Use g++ to link all .o files

Calling C++ from FORTRAN Functions called by FORTRAN code must accept pointers to non-array arguments, because FORTRAN passes by reference In C++ code (as opposed to C), precede function declarations with extern "C" End function names with _ Remember matrix storage conventions!

On the FORTRAN side Leave out _ at end of C/C++ function names, FORTRAN compiler adds them automatically Declare functions as external, like other external FORTRAN routines Pass arguments normally (ignore that they are pointers on the C/C++ side) A double in C++ corresponds to type double precision in FORTRAN

Linking C++ with FORTRAN Use gfortran –c to compile each FORTRAN source file Use g++ -c to compile each C++ source file Use gfortran to link all .o files If C++ code uses any Standard Library code, must explicitly link with it Library name is libstdc++.so

Next Time Mop-up! Final project discussion Loading dynamic libraries in UNIX private and friend classes More overloading