Android NDK. Federico Menozzi & Srihari Pratapa
|
|
- Roger Day
- 5 years ago
- Views:
Transcription
1 Android NDK Federico Menozzi & Srihari Pratapa
2 Resources C++ CMake NDK JNI (optional)
3 Android Stack
4 NDK? JNI? What? NDK Native Development Kit Allows developers to create Android applications with C/C++ Uses JNI to allow for Java/native interop JNI Java Native Interface Allows for Java to call native (i.e. C/C++) code and vice-versa Used as a bridge between Android system and native code
5 What is C++? High-performance systems-level programming language Supports imperative, object-oriented, and functional programming patterns Created to be a (nearly) strict superset of C This means most C programs are also valid C++ programs
6 Who Cares About C++? Literally everyone People who care about performance People who care about abstraction Masochists Used to create operating systems, web browsers, compilers/interpreters, network stacks, database, graphics/game engines, etc.
7 C++ for Idiots Java Programmers
8 A Quick Word About C++... Fiendishly complicated Outrageously complex Tutorial will focus on writing very basic C++ in a similar manner to Java But C++ can do SO much more...
9 C++ Basics Compiled, statically-typed (like Java) Nearly backwards-compatible with C Separates class/function declarations from definitions (unlike Java) Declarations stored in header files (.h,.hpp,.hxx, etc.) Definitions stored in source files (.cc,.cpp,.cxx, etc.) Source files are compiled into object files, which then pass through the linker to become the final executable
10 C++ Program Lifecycle
11 Hello World HelloWorld.java (Java) HelloWorld.cpp (C++) public class HelloWorld { public static void main(string[] args) { System.out.println( Hello, World! ); } } #include <iostream> int main(int argc, char* argv[]) { std::cout << Hello, World!\n ; return 0; } Compile and run: javac HelloWorld.java && java HelloWorld Compile and run (uses GCC): g++ HelloWorld.cpp -o hello &&./hello
12 C++ Basics - Primitive Types Compared with Java s nine primitive types (boolean, byte, char, short, int, long, float, double, and void), C++ has many primitive types
13 C++ Basics - Control Flow Branching constructs (if/else, switch) are identical to Java Looping constructs (for/while/do-while) are also identical to Java One exception: Java s for each construct (for (Type t : collection) { } ) is only available in C++11 and onwards
14 C++ Basics - Functions Unlike Java, functions in C++ can be free-floating and not tied to a class Otherwise, quite similar to Java #include <cstdio> // Print some values using C s printf() function void foo(int i, float f, bool b) { std::printf( i: %d, f: %f, b: %d\n, i, f, b); }
15 C++ Basics - Functions Typically, C++ functions (and classes) are split into their declarations (header file) and their definitions (source file) myfunc.h myfunc.cpp // Declare function prototype void foo(int a); #include myfunc.h // Define function void foo(int a) { //... }
16 C++ Basics - Classes Also fairly similar to Java Can be defined with either class or struct keywords struct member visibility defaults to public, class to private Unlike Java, classes can either be allocated on the stack or on the heap We ll get back to this
17 C++ Basics - Classes Like functions, C++ classes are split into their declarations (header file) and their definitions (source file) MyClass.h MyClass.cpp // Declare class prototype class MyClass { public: MyClass( int n); // Constructor int n; // Field private: void foo(); // Method }; #include MyClass.h MyClass::MyClass( int n) { //... } void MyClass::foo() { //... }
18 Detour - Stack vs Heap
19 C++ Basics - Classes #include MyClass.h int main() { // Create new class instance on stack (memory // deallocated automatically at end of main()) MyClass m1(1); m1.n = 42; // Create new class instance on heap (memory // must be deallocated manually via delete!) MyClass* m2 = new MyClass(2); if (m2!= NULL) { // Or nullptr in C++11 and onwards m2->n = 42; } delete m2; }
20 C++ Basics - Arrays Inherits arrays directly from C Unlike Java arrays, C/C++ arrays can be allocated on either the stack or the heap Unlike Java arrays, C/C++ arrays are not objects Basically just pointers to blocks of memory (whether stack or heap allocated) Don t carry their length around with them So-called C-style strings are just arrays of char WARNING: C-style strings must include room for the null terminator \0
21 C++ Basics - Arrays int main() { // Allocate an uninitialized array of 20 ints on stack int arr1[20]; arr1[0] = 1; // Allocate and initialize an array of 5 ints on int arr2[] = { 1,2,3,4,5}; stack // Allocate an array of 20 ints on heap. Must be freed // manually using delete[] (note the brackets for arrays!) int* arr3 = new int[20]; delete[] arr3; }
22 C++ Basics - Arrays int main() { // Allocate an uninitialized string of length 19 (plus null // terminator) on stack char str1[20]; // Allocate and initialize a string of length 5 onstack with // room for the null terminator char str2[] = { H, e, l, l, o, \0 ]; // Allocate and initialize a string from a string literal onstack, // which automatically includes the null terminator for you char str3[] = Hello ; // Get pointer to READ-ONLY literal (stored in static section, can t // be modified) const char* str4 = Hello ; // Allocate a string of length 19 (plus null terminator) onheap. // Must be freed manually using delete[] (note the brackets for arrays!) char* str5 = new char[20]; delete[] str5; }
23 Arrays and C-Style Strings Suck Don t use them Too many ways to do it wrong Must manually keep track of length/capacity If dynamically allocated, must free memory yourself They exist purely for compatibility with C For C++, we have std::vector<t> and std::string, respectively
24 std::vector<t> Analogous to Java s ArrayList<T> See #include <vector> #include <cstdio> int main() { std::vector<int> v; v.push_back(1); v.push_back(2); v.push_back(3); if (v.size() == 3) { // Can also use v.at(2) to access value with bounds checking std::printf( Three things. Last item: %d\n, v[2]); } } // v s memory is automatically freed here
25 std::string Analogous to Java s String See #include <string> #include <cstdio> int main() { std::string s1 = Hello ; std::string s2 = World ; if (s1!= s2) { std::string greeting = s1 +, + s2 +! ; std::printf( %s\n, greeting.c_str()); //.c_str() gets the underlying char* } } // s1 s/s2 s memory is automatically freed here
26 C++ Tips If you don t need polymorphism or nullable objects, don t use pointers Stack allocation is easier to keep track of (at the cost of performance for large objects) If you do need polymorphism, don t use raw new/delete: smart pointers like std::unique_ptr<t> and std::shared_ptr<t> manage memory for you (if you re using C++11) Prefer C++ to C when writing C++ Don t use raw arrays; use std::vector<t> instead Don t use raw char* strings; use std::string instead
27 CMake Cross-platform meta-build system Meta-build system De-facto standard C++ build system for cross-platform projects Generates other build files that do the actual building Can generate Makefiles (Linux), Xcode projects (MacOS), Visual Studio solutions (Windows), and many more Build process is described using CMake s custom scripting language in a file called CMakeLists.txt
28 CMakeLists.txt # Set minimum CMake version cmake_minimum_required(version 3.0) # Set project name project(hello-world) # Create SOURCES variable set(sources src/main.cpp) # Create executable named main from SOURCES variable add_executable(main ${SOURCES})
29 CMake - Hello World. build CMakeLists.txt src main.cpp src/main.cpp #include <cstdio> int main() { std::printf( Hello, World!\n ); return 0; }
30
31 What We Didn t Cover Polymorphism References Special Member Functions/Rule of 3/5/0 Operator Overloading Const-Correctness Standard library Most Standard Template Library (STL) containers and algorithms Rvalue references and move semantics Smart pointers Templates Advanced CMake
32 Project Prerequisites - Get the Tools
33 Sample Project
34 Set your paths Remember to make sure you set your NDK path ndk.dir=$yourpath$/android/sdk/ndk-bundle
35 Changes in gradle CMake Compile options externalnativebuild { cmake { path "src/main/cpp/cmakelists.txt" argumetns '-DANDROID_TOOLCHAIN=clang', '-DANDROID_TOOLCHAIN=clang' cppflags '...' cflags } } '...'
36 Native Functions Java functions that are used to call functions in your C/C++ code. Use the keyword native to distinguish from other functions. public native ReturnType FuncName(argruments...); Declare all the native functions in your one place (MainActivity)
37 Native functions Example Declarations // Return type string. Void parameters public native String stringfromjni(); //Return type void. Int parameters public native void SetWidth(int width); //Function to add two numbers public native int AddNums(int a, int b);
38 Load the C/C++ library Let Java know about the function calls in your C/C++ System.loadLibrary("LibName"); LibName - Library built from your C/C++ code Make sure to include that code in static block Static { System.loadLibrary("LibName"); }
39 Java JNI interface C/C++ Java provides a way(not exactly an interface) for C/C++ functions to be callable from JAVA. #include<jni.h> ( A Header file) Defines two variables JNIEnv*, JavaVM* Make sure you include this header file in your C/C++ code All declarations, data types, preprocessing definitions are in this header file
40 JNI data types
41 JNI reference types
42 JNI C Code // Java Code public native ReturnType FuncName(argruments...); Application ID: Mentioned in gradle file // C Code #include<jni.h> JNIEXPORT JNIReturnType JNICALL Java_ApplicationID_ClassName_FuncName( JNIEnv* env, jobject thiz, arguments... ) { };
43 JNI C functions applicationid 'com.example.hellojni' classname HelloJNI //Return type string. Void parameters public native String stringfromjni(); // Corresponding C function JNIEXPORT jstring JNICALL Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz); //Return type public native //Function to public native void. Int parameters void SetWidth(int width); add two numbers int AddNums(int a, int b);
44 JNI C functions applicationid 'com.example.hellojni' classname HelloJNI //Return type string. Void parameters public native String stringfromjni(); // Corresponding C function JNIEXPORT jstring JNICALL Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz); //Return type void. Int parameters public native void SetWidth(int width);??????????????????????????????????? ( C/C++ Function?) //Function to add two numbers public native int AddNums(int a, int b);??????????????????????????????????? ( C/C++ Function?)
45 JNI C functions applicationid 'com.example.hellojni' classname HelloJNI //Return type void. Int parameters public native void SetWidth(int width); JNIEXPORT void JNICALL Java_com_example_hellojni_HelloJni_SetWidth( JNIEnv* env, jobject thiz, jint width); //Function to add two numbers public native int AddNums(int a, int b); JNIEXPORT int JNICALL Java_com_example_hellojni_HelloJni_AddNums( JNIEnv* env, jobject thiz, jint a, jint b);
46 JNI C++ functions #include<jni.h> extern "C" { //JNI Native C functions JNIEXPORT JNIReturnType JNICALL Java_ApplicationID_ClassName_FuncName( JNIEnv* env, jobject thiz, arguments... ) { }; }
47 Calling Java Functions Java functions can be called from native code ( C/C++) #include<jni.h> ( A Header file) Defines two variables JNIEnv*, JavaVM* Defines several functions to retrieve classes, methods, and variables
48 JNI Functions Some of the widely used functions jclass FindClass(JNIEnv *env, const char *name); jmethodid GetMethodID(JNIEnv *env, jclass clazz,const char *name, const char *sig); NativeType Call<type>Method(JNIEnv *env, jobject obj,jmethodid methodid,...) jfieldid GetFieldID(JNIEnv *env, jclass clazz,const char *name, const char *sig);
49 JNI Functions Using the JNI functions in C/C++ code Create objects of Java classes Get Methods of the classes Call private, public, and static methods of the classes
50 Constructor like function Special native function called when System.loadLibrary call is made JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved); Use this function load and save several environmental variables Corresponding JNI_OnUnLoad() function exists to free memories
51 Example OnLoad Code JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { JNIEnv* env; if ((*vm)->getenv(vm, (void**)&env, JNI_VERSION_1_6)!= JNI_OK) { return JNI_ERR; // JNI version not supported. } } Let s look at a detailed example of callbacks
52 Questions? Link to code: Examples discussed in class hello-jni, hello-jnicallback Advanced examples hello-gls, native-activity, native-audio
53 Points to cover Settings side Java Side Path of the NDK set Changes in gradle Add dependencies and path to CMake Declaring native functions Setting the load library name on start up Calling a C function code Talk ( code optimization) C/C++ Side What is a Java JNI - one slide recap Data types ( jclass, jmethod, jobject, jint, jstring ) Declaring a JNI callable function in C ( if in C++ use extern) Signature of the function Parameters passed!
Lecture 5 - NDK Integration (JNI)
Lecture 5 - NDK Integration (JNI) This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/
More informationJava Native Interface. Diego Rodrigo Cabral Silva
Java Native Interface Diego Rodrigo Cabral Silva Overview The JNI allows Java code that runs within a Java Virtual Machine (VM) to operate with applications and libraries written in other languages, such
More informationCalling C Function from the Java Code Calling Java Method from C/C++ Code
Java Native Interface: JNI Calling C Function from the Java Code Calling Java Method from C/C++ Code Calling C Functions From Java Print Hello Native World HelloNativeTest (Java) HelloNative.c HelloNative.h
More informationLecture 2, September 4
Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due
More informationCE221 Programming in C++ Part 1 Introduction
CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab
More informationInvoking Native Applications from Java
2012 Marty Hall Invoking Native Applications from Java Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/java.html Customized Java EE Training: http://courses.coreservlets.com/
More informationNDK Integration (JNI)
NDK Integration (JNI) Lecture 6 Operating Systems Practical 9 November 2016 This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
More informationPRINCIPLES OF OPERATING SYSTEMS
PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)
More informationAnnouncements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy
CSCI 334: Principles of Programming Languages Lecture 18: C/C++ Homework help session will be tomorrow from 7-9pm in Schow 030A instead of on Thursday. Instructor: Dan Barowy HW6 and HW7 solutions We only
More informationJAVA Native Interface
CSC 308 2.0 System Development with Java JAVA Native Interface Department of Statistics and Computer Science Java Native Interface Is a programming framework JNI functions written in a language other than
More informationC++ Tutorial AM 225. Dan Fortunato
C++ Tutorial AM 225 Dan Fortunato Anatomy of a C++ program A program begins execution in the main() function, which is called automatically when the program is run. Code from external libraries can be
More informationJava/JMDL communication with MDL applications
m with MDL applications By Stanislav Sumbera [Editor Note: The arrival of MicroStation V8 and its support for Microsoft Visual Basic for Applications opens an entirely new set of duallanguage m issues
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More information377 Student Guide to C++
377 Student Guide to C++ c Mark Corner January 21, 2004 1 Introduction In this course you will be using the C++ language to complete several programming assignments. Up to this point we have only provided
More informationLecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8
Today... Java basics S. Bowers 1 of 8 Java main method (cont.) In Java, main looks like this: public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World!"); Q: How
More informationOutline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring
Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationCommon Misunderstandings from Exam 1 Material
Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself
More informationPorting Guide - Moving Java applications to 64-bit systems. 64-bit Java - general considerations
Porting Guide - Moving Java applications to 64-bit systems IBM has produced versions of the Java TM Developer Kit and Java Runtime Environment that run in true 64-bit mode on 64-bit systems including IBM
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationWe can also throw Java exceptions in the native code.
4. 5. 6. 7. Java arrays are handled by JNI as reference types. We have two types of arrays: primitive and object arrays. They are treated differently by JNI. Primitive arrays contain primitive data types
More informationArrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors
Arrays Returning arrays Pointers Dynamic arrays Smart pointers Vectors To declare an array specify the type, its name, and its size in []s int arr1[10]; //or int arr2[] = {1,2,3,4,5,6,7,8}; arr2 has 8
More informationWhen C++ wants to meet Java
When C++ wants to meet Java Designing cppjni framework Michał Łoś (michal.los@nokia.com) 1 Agenda //BTW: I hate agendas.. using cppjniagenda = mpl::list < Motivation, InitialDesignDecisions, HowDoesThingsWorkInCppJNI,
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationJava Basic Syntax. Java vs C++ Wojciech Frohmberg / OOP Laboratory. Poznan University of Technology
Java vs C++ 1 1 Department of Computer Science Poznan University of Technology 2012.10.07 / OOP Laboratory Outline 1 2 3 Outline 1 2 3 Outline 1 2 3 Tabular comparizon C++ Java Paradigm Procedural/Object-oriented
More informationCSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010
CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)
More informationEMBEDDED SYSTEMS PROGRAMMING Android NDK
EMBEDDED SYSTEMS PROGRAMMING 2017-18 Android NDK WHAT IS THE NDK? The Android NDK is a set of cross-compilers, scripts and libraries that allows to embed native code into Android applications Native code
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects
More informationModern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi
Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Move semantics Classes Operator overloading Making your class copyable Making your class movable Rule of all or nothing Inheritance
More informationCSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 8 C: Miscellanea Control, Declarations, Preprocessor, printf/scanf 1 The story so far The low-level execution model of a process (one
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationTutorial 1: Introduction to C Computer Architecture and Systems Programming ( )
Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough
More informationIntroductory Seminar
EDAF80 Introduction to Computer Graphics Introductory Seminar OpenGL & C++ Michael Doggett 2017 C++ slides by Carl Johan Gribel, 2010-13 Today Lab info OpenGL C(++)rash course Labs overview 5 mandatory
More informationAn overview of Java, Data types and variables
An overview of Java, Data types and variables Lecture 2 from (UNIT IV) Prepared by Mrs. K.M. Sanghavi 1 2 Hello World // HelloWorld.java: Hello World program import java.lang.*; class HelloWorld { public
More information377 Student Guide to C++
377 Student Guide to C++ c Mark Corner, edited by Emery Berger January 23, 2006 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due to
More informationOutline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O
Outline EDAF30 Programming in C++ 2. Introduction. More on function calls and types. Sven Gestegård Robertz Computer Science, LTH 2018 1 Function calls and parameter passing 2 Pointers, arrays, and references
More informationLecture 6 - NDK Integration (JNI)
Lecture 6 - NDK Integration (JNI) This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/
More informationMultimedia-Programmierung Übung 3
Multimedia-Programmierung Übung 3 Ludwig-Maximilians-Universität München Sommersemester 2016 Ludwig-Maximilians-Universität München Multimedia-Programmierung 1-1 Today Ludwig-Maximilians-Universität München
More informationSUB CODE:IT0407 SUB NAME:INTEGRATIVE PROGRAMMING & TECHNOLOGIES SEM : VII. N.J.Subashini Assistant Professor,(Sr. G) SRM University, Kattankulathur
SUB CODE:IT0407 SUB NAME:INTEGRATIVE PROGRAMMING & TECHNOLOGIES SEM : VII N.J.Subashini Assistant Professor,(Sr. G) SRM University, Kattankulathur 1 UNIT I 2 UNIT 1 LANGUAGE INTEROPERABILITY IN JAVA 9
More informationCS3157: Advanced Programming. Outline
CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching
More informationLEVERAGING EXISTING PLASMA SIMULATION CODES. Anna Malinova, Vasil Yordanov, Jan van Dijk
136 LEVERAGING EXISTING PLASMA SIMULATION CODES Anna Malinova, Vasil Yordanov, Jan van Dijk Abstract: This paper describes the process of wrapping existing scientific codes in the domain of plasma physics
More informationHomework 4. Any questions?
CSE333 SECTION 8 Homework 4 Any questions? STL Standard Template Library Has many pre-build container classes STL containers store by value, not by reference Should try to use this as much as possible
More informationG52CPP C++ Programming Lecture 3. Dr Jason Atkin
G52CPP C++ Programming Lecture 3 Dr Jason Atkin E-Mail: jaa@cs.nott.ac.uk 1 Revision so far C/C++ designed for speed, Java for catching errors Java hides a lot of the details (so can C++) Much of C, C++
More informationNDK OVERVIEW OF THE ANDROID NATIVE DEVELOPMENT KIT
ANDROID NDK OVERVIEW OF THE ANDROID NATIVE DEVELOPMENT KIT Peter R. Egli INDIGOO.COM 1/16 Contents 1. What you can do with NDK 2. When to use native code 3. Stable APIs to use / available libraries 4.
More informationCS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor
CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static
More informationOutline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C
Lecture 1 C primer What we will cover A crash course in the basics of C You should read the K&R C book for lots more details Various details will be exemplified later in the course Outline Overview comparison
More informationChapter 1 Getting Started
Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different
More information1 class HelloWorld 2 { 3 public native void displayhelloworld(); 4 static 5 { 6 System.loadLibrary("hello"); 7 }
JNI Java Native Interface C and C++. JNI and STL Alan Mycroft University of Cambridge (heavily based on previous years notes thanks to Alastair Beresford and Andrew Moore) Michaelmas Term 2012 20 Java
More informationAssumptions. History
Assumptions A Brief Introduction to Java for C++ Programmers: Part 1 ENGI 5895: Software Design Faculty of Engineering & Applied Science Memorial University of Newfoundland You already know C++ You understand
More informationC and C++ 8. JNI and STL. Alan Mycroft. University of Cambridge (heavily based on previous years notes thanks to Alastair Beresford and Andrew Moore)
C and C++ 8. JNI and STL Alan Mycroft University of Cambridge (heavily based on previous years notes thanks to Alastair Beresford and Andrew Moore) Michaelmas Term 2013 2014 1 / 41 JNI and STL This lecture
More informationCS 231 Data Structures and Algorithms, Fall 2016
CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard
More informationJNI and STL. Justification
JNI and STL C and C++. JNI and STL Alan Mycroft University of Cambridge (heavily based on previous years notes thanks to Alastair Beresford and Andrew Moore) Michaelmas Term 2013 201 This lecture looks
More informationEMBEDDED SYSTEMS PROGRAMMING Android NDK
EMBEDDED SYSTEMS PROGRAMMING 2014-15 Android NDK WHAT IS THE NDK? The Android NDK is a set of cross-compilers, scripts and libraries that allows to embed native code into Android applications Native code
More informationDatabase Systems on Modern CPU Architectures
Database Systems on Modern CPU Architectures Introduction to Modern C++ Moritz Sichert Technische Universität München Department of Informatics Chair of Data Science and Engineering Overview Prerequisites:
More informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More informationthe gamedesigninitiative at cornell university Lecture 7 C++ Overview
Lecture 7 Lecture 7 So You Think You Know C++ Most of you are experienced Java programmers Both in 2110 and several upper-level courses If you saw C++, was likely in a systems course Java was based on
More informationKickstart Intro to Java Part I
Kickstart Intro to Java Part I COMP346/5461 - Operating Systems Revision 1.6 February 9, 2004 1 Topics Me, Myself, and I Why Java 1.2.*? Setting Up the Environment Buzz about Java Java vs. C++ Basic Java
More informationC Introduction. Comparison w/ Java, Memory Model, and Pointers
CS 261 Fall 2018 Mike Lam, Professor C Introduction Comparison w/ Java, Memory Model, and Pointers Please go to socrative.com on your phone or laptop, choose student login and join room LAMJMU The C Language
More informationCS
CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Programming in C++ First, some praise for C++ "It certainly has its good points. But by and large I think it s a bad language. It does a lot of things half well and
More informationCSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many
More informationeingebetteter Systeme
Praktikum: Entwicklung interaktiver eingebetteter Systeme C++-Tutorial (falk@cs.fau.de) 1 Agenda Classes Pointers and References Functions and Methods Function and Operator Overloading Template Classes
More informationFinal CSE 131B Spring 2004
Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)
More informationProgramming refresher and intro to C programming
Applied mechatronics Programming refresher and intro to C programming Sven Gestegård Robertz sven.robertz@cs.lth.se Department of Computer Science, Lund University 2018 Outline 1 C programming intro 2
More informationCS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms
CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms AUTO POINTER (AUTO_PTR) //Example showing a bad situation with naked pointers void MyFunction()
More informationJava TM Native Methods. Rex Jaeschke
Java TM Native Methods Rex Jaeschke Java Native Methods 1999, 2007, 2009 Rex Jaeschke. All rights reserved. Edition: 2.0 (matches JDK1.6/Java 2) All rights reserved. No part of this publication may be
More information1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!
//Example showing a bad situation with naked pointers CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms void MyFunction() MyClass* ptr( new
More informationCPSC 427: Object-Oriented Programming
CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 11 October 3, 2018 CPSC 427, Lecture 11, October 3, 2018 1/24 Copying and Assignment Custody of Objects Move Semantics CPSC 427, Lecture
More informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationAdvanced Systems Programming
Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short
More informationIntroduction to Java
Introduction to Java Module 1: Getting started, Java Basics 22/01/2010 Prepared by Chris Panayiotou for EPL 233 1 Lab Objectives o Objective: Learn how to write, compile and execute HelloWorld.java Learn
More informationDisclaimer. We are going to cover a lot in these slides. Though previous knowledge of C is helpful, it is not required to do well in this course.
Intro to C++ 1/84 Disclaimer We are going to cover a lot in these slides. Though previous knowledge of C is helpful, it is not required to do well in this course. Please ask questions and come see us afterwards
More informationCSE 333 Lecture 9 - intro to C++
CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia & Agenda Main topic: Intro to C++ But first: Some hints on HW2 Labs: The
More informationC and C++ I. Spring 2014 Carola Wenk
C and C++ I Spring 2014 Carola Wenk Different Languages Python sum = 0 i = 1 while (i
More informationAgenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures
The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF
More informationEMBEDDED SYSTEMS PROGRAMMING Android NDK
EMBEDDED SYSTEMS PROGRAMMING 2015-16 Android NDK WHAT IS THE NDK? The Android NDK is a set of cross-compilers, scripts and libraries that allows to embed native code into Android applications Native code
More informationWhy C++ is much more fun than C (C++ FAQ)?
From C to C++ Why C++ is much more fun than C (C++ FAQ)? 1. Classes & methods - OO design 2. Generic programming - Templates allow for code reuse 3. Stricter type system (e.g. function args) 4. Some run-time
More informationOBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe
OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++
More informationAnnouncements. Lecture 04b Header Classes. Review (again) Comments on PA1 & PA2. Warning about Arrays. Arrays 9/15/17
Announcements Lecture 04b Sept. 14 th, 2017 Midterm #1: Sept. 26 th (week from Tuesday) Code distributed one week from today PA2 test cases & answers posted Quiz #4 next Tuesday (before class) PA3 due
More informationMotivation was to facilitate development of systems software, especially OS development.
A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.
More informationStructs. Contiguously-allocated region of memory Refer to members within structure by names Members may be of different types Example: Memory Layout
Structs (C,C++) 2 Structs Contiguously-allocated region of memory Refer to members within structure by names Members may be of different types Example: struct rec int i; int a[3]; int *p; Memory Layout
More informationUNDEFINED BEHAVIOR IS AWESOME
UNDEFINED BEHAVIOR IS AWESOME Piotr Padlewski piotr.padlewski@gmail.com, @PiotrPadlewski ABOUT MYSELF Currently working in IIIT developing C++ tooling like clang-tidy and studying on University of Warsaw.
More informationCSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington
CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia New exercise posted yesterday afternoon, due Monday morning - Read a directory
More informationC++ Programming Lecture 4 Software Engineering Group
C++ Programming Lecture 4 Software Engineering Group Philipp D. Schubert VKrit Date: 24.11.2017 Time: 15:45 h Your opinion is important! Please use the free text comments Contents 1. Operator overloading
More informationSeparate Compilation Model
Separate Compilation Model Recall: For a function call to compile, either the function s definition or declaration must appear previously in the same file. Goal: Compile only modules affected by recent
More informationInlining Java Native Calls at Runtime
Inlining Java Native Calls at Runtime (CASCON 2005 4 th Workshop on Compiler Driven Performance) Levon Stepanian, Angela Demke Brown Computer Systems Group Department of Computer Science, University of
More informationMotivation was to facilitate development of systems software, especially OS development.
A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.
More informationKurt Schmidt. October 30, 2018
to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed
More informationMaking use of Android
What else can you do with Android? Chris Simmonds, 2net Limited Class TU-3.2 Copyright 2010, 2net Limited 1 Overview Creating a project Writing the app Writing native code libraries Other native code 2
More informationG52CPP C++ Programming Lecture 9
G52CPP C++ Programming Lecture 9 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture const Constants, including pointers The C pre-processor And macros Compiling and linking And
More informationCS 220: Introduction to Parallel Computing. Beginning C. Lecture 2
CS 220: Introduction to Parallel Computing Beginning C Lecture 2 Today s Schedule More C Background Differences: C vs Java/Python The C Compiler HW0 8/25/17 CS 220: Parallel Computing 2 Today s Schedule
More informationObject Reference and Memory Allocation. Questions:
Object Reference and Memory Allocation Questions: 1 1. What is the difference between the following declarations? const T* p; T* const p = new T(..constructor args..); 2 2. Is the following C++ syntax
More informationLecture 2 summary of Java SE section 1
Lecture 2 summary of Java SE section 1 presentation DAD Distributed Applications Development Cristian Toma D.I.C.E/D.E.I.C Department of Economic Informatics & Cybernetics www.dice.ase.ro Cristian Toma
More informationProgramming Language Concepts: Lecture 2
Programming Language Concepts: Lecture 2 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2011 PLC 2011, Lecture 2, 6 January 2011 Classes and
More informationProgrammazione. Prof. Marco Bertini
Programmazione Prof. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Hello world : a review Some differences between C and C++ Let s review some differences between C and C++ looking
More informationPHY4321 Summary Notes
PHY4321 Summary Notes The next few pages contain some helpful notes that summarize some of the more useful material from the lecture notes. Be aware, though, that this is not a complete set and doesn t
More informationG52CPP C++ Programming Lecture 7. Dr Jason Atkin
G52CPP C++ Programming Lecture 7 Dr Jason Atkin 1 This lecture classes (and C++ structs) Member functions inline functions 2 Last lecture: predict the sizes 3 #pragma pack(1) #include struct A
More informationCSE 333 Midterm Exam 7/29/13
Name There are 5 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed
More informationA brief introduction to C programming for Java programmers
A brief introduction to C programming for Java programmers Sven Gestegård Robertz September 2017 There are many similarities between Java and C. The syntax in Java is basically
More informationROS2 for Android, ios and Universal Windows Platform. Esteve Fernandez
ROS2 for Android, ios and Universal Windows Platform Esteve Fernandez esteve@apache.org Outline Introduction The ROS2 architecture Overview of the changes needed in ROS2 rcljava, rclobjc and rcldotnet
More information