pptx

advertisement
CISC/CMPE320
•
•
•
•
Presentations next week.
Final Exam Preparation page is posted.
Redmine pages are public.
Moodle surveys available today.
• Presentation stuff again.
• C++/CLI
Fall 2015
CISC/CMPE320 - Prof. McLeod
1
Week 12 Team Presentations
• Demonstrate of the fruit of your efforts!
• And, summarize (in any order you wish):
– How work ended up being distributed and when it was
completed.
– Difficulties faced and overcome.
– Difficulties not overcome.
– Good/bad library use.
– Work left to do, if any.
– Team techniques that worked and those that did not.
– What you would do differently if you had to do this
again…
Fall 2015
CISC/CMPE320 - Prof. McLeod
2
Presentation Schedule – Week 12
• Tuesday, Dec. 1 – Basswood, Beech, Cherry,
Tamarack.
• Thursday, Dec. 3, Lecture Time – Hickory, Maple,
Oak, Birch.
• Thursday, Dec. 3, Tutorial Time (JEF 128) –
Poplar, BalsamFir, Spruce, Cedar.
• Friday, Dec. 4 – Hemlock, JackPine, Walnut,
WhitePine.
Fall 2015
CISC/CMPE320 - Prof. McLeod
3
C++/CLI in VS2015 – What’s New?
• ISO C++11 standards are all pretty much
complete. Some C++14 and C++17 standards
are met. Same for the STL.
• Faster build times.
• IntelliSense improvements.
• Better refactoring (including “Move Function
Definition”…).
• Additions to diagnostics.
• Can target Windows 10 (and other devices).
• Better graphics diagnostics and GPU usage.
Fall 2015
CISC/CMPE320 - Prof. McLeod
4
C++/CLI
• “Common Language Infrastructure”
• A language built on top of ISO/C++ by Microsoft.
• The CLR in .NET (“Common Language Runtime”)
allows you to include C, ISO/C++ and C++/CLI in
the same program and still compile it.
Fall 2015
CISC/CMPE320 - Prof. McLeod
5
Some C++/CLI Resources
• Non-microsoft tutorial:
http://www.functionx.com/cppcli/index.htm
• MSDN Summary/Starting Page:
https://msdn.microsoft.com/en-us/library/60k1461a.aspx
• Books:
• “Pro Visual C++/CLI and the .NET 3.5 Platform”
by Stephen RG Fraser, Apress (2009)
• “Microsoft Visual C++/CLI Step by Step”, by Julian
Templeman, Microsoft (2013)
Fall 2015
CISC/CMPE320 - Prof. McLeod
6
Herb Sutter
• Microsoft’s lead architect for C++/CLI.
• Deeply involved in the ISO C++ standards
committee.
• Wrote “Exceptional C++”, “More Exceptional C++”
and “Exceptional C++ Style”.
• The rational for the structure of C++/CLI (from
2006):
http://www.gotw.ca/publications/C++CLIRationale.pdf
Fall 2015
CISC/CMPE320 - Prof. McLeod
7
What Bjarne Thinks…
• http://www.stroustrup.com/bs_faq.html#CppCLI
• “…The wealth of new language facilities in
C++/CLI compared to ISO Standard C++ tempts
programmers to write non-portable code that
(often invisibly) become intimately tied to
Microsoft Windows. …”
Fall 2015
CISC/CMPE320 - Prof. McLeod
8
CIL
• “Common Intermediate Language”
• Looks like assembly language, but is CPU
independent.
• The CLR generates CIL as part of an Assembly.
• The Assembly is the main building block of the
.NET Framework.
• Created after compilation and has a *.exe or *.dll
extension.
• An Assembly also contains Assembly Metadata,
Type Metadata and Resources (like string tables,
images and cursors, for example).
Fall 2015
CISC/CMPE320 - Prof. McLeod
9
.NET Framework
• Other .NET languages, such as C#, Visual Basic
2008+ and JScript each have their own compilers
which generate CIL code.
• The JIT (“Just In Time”) compiler is responsible
for compiling CIL and the metadata to machine
code. (“RyuJIT” included in .NET Framework 4.6
for x64)
• Microsoft claims that the JIT is just as fast as
running an *.exe that is already in native code
because the JIT can target specific processors.
• (CIL used to be called “MSIL”.)
Fall 2015
CISC/CMPE320 - Prof. McLeod
10
CIL Example
• A C# program:
using System;
public class Hello {
public static void Main(String[] args) {
Console.WriteLine("Hello World!");
}
}
• The generated CIL is on the next two slides. The
metadata section is included.
Fall 2015
CISC/CMPE320 - Prof. McLeod
11
// Metadata version: v2.0.50215
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 2:0:0:0
}
.assembly sample
{
.custom instance void
[mscorlib]System.Runtime.CompilerServices.CompilationRelax
ationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00)
.hash algorithm 0x00008004 .ver 0:0:0:0
}
.module sample.exe // MVID: {A224F460-A049-4A03-9E7180A36DBBBCD3}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x02F20000
Fall 2015
CISC/CMPE320 - Prof. McLeod
12
.class public auto ansi beforefieldinit Hello extends
[mscorlib]System.Object
{
.method public hidebysig static void Main(string[] args) cil
managed
{
.entrypoint // Code size 13 (0xd)
.maxstack 8
IL_0000: nop
IL_0001: ldstr "Hello World!"
IL_0006: call void
[mscorlib]System.Console::WriteLine(string)
IL_000b: nop
IL_000c: ret
} // end of method Hello::Main
.method public hidebysig specialname rtspecialname instance void
.ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method Hello::.ctor
} // end of class Hello
Fall 2015
CISC/CMPE320 - Prof. McLeod
13
.NET Framework, Cont.
• This mechanism allows for:
– Common data types are shared by all languages.
– Object handles from one language can be passed as a
an argument to a method in another language.
– Methods from other languages can be invoked.
– Classes can contain instances of objects written in
another language.
– You can inherit from a class created in another
language.
– IDE and debugger should be same for all languages
(Visual Studio).
Fall 2015
CISC/CMPE320 - Prof. McLeod
14
.NET Framework, Cont.
• Of course Microsoft is only interested in Windows
platforms: 32 or 64 bit: Windows Server 2003,
2008, XP, Vista (yuk!), 7, 8, 8.1, 10. Phone 8.1.
• But any processor…
• If you want different platforms (Linux, Mac, etc.)
you could use use MonoDevelop
(monodevelop.org) or CodeBlocks?.
• New: “Visual Studio Code”. Optimized for Web
and Cloud applications. Runs on Mac & Linux.
See:
https://code.visualstudio.com/
Fall 2015
CISC/CMPE320 - Prof. McLeod
15
.NET on a Mac
• But, now you can install and run .NET on a Mac –
see:
https://msdn.microsoft.com/en-us/library/windows/apps/jj945492.aspx
• Use “Boot Camp”, “Parallels Desktop”, “Virtual
Box” or “VMware Fusion”.
• (Or just buy a real computer in the first place!)
Fall 2015
CISC/CMPE320 - Prof. McLeod
16
.NET Framework – Features
• No “DLL Hell”! You are sheltered almost 100%
from the Win API. No more having to figure out
all those dll function calls!
• Provides a consistent programming and
debugging framework for all languages, with
integrated XML documentation capabilities.
• If you write only Managed Code, then you do not
have to do any manual garbage collection. Use
handles instead of pointers and C++/CLI instead
of ISO/C++. (gcnew and ^, instead of new and *)
Fall 2015
CISC/CMPE320 - Prof. McLeod
17
.NET Framework – Features, Cont.
• COM (“Component Object Model”) and COM+ are
no longer a part of .NET. You can still use them,
but the components are wrapped in a class
library.
• Deployments no longer use the registry or special
folders.
• Deployment is much easier.
Fall 2015
CISC/CMPE320 - Prof. McLeod
18
CTS – “Common Type System”
• (These acronyms!!)
• Provides OO framework for all data types for all
.NET languages.
• Provides a set of constraints that data types must
adhere to if the language is to be .NET
compatible.
• Provides the framework for “interlanguage
integration” and data type safety.
Fall 2015
CISC/CMPE320 - Prof. McLeod
19
CTS, Cont.
• Any unmanaged pointer type will be stored on the
C Runtime (“CRT”) heap, as opposed to the
managed heap.
• “Unmanaged” is also called “Un-safe”…
Fall 2015
CISC/CMPE320 - Prof. McLeod
20
CLS – “Common Language Specification”
• Any parts of a .NET language that will be exposed
for use by other .NET languages must adhere to
the CLS.
• The language can have whatever else it wants,
but the part that is to be used by another
language must be CLS only.
Fall 2015
CISC/CMPE320 - Prof. McLeod
21
Some CLS Rules
• No Global methods or variables.
• No case sensitivity – so make sure variable names differ
by more than just case.
• The only primitive types that can be used are: Byte,
Int16, Int32, Int64, Single, Double, Boolean, Char,
Decimal, IntPtr, String.
• No variable length argument lists.
• No pointers.
• Must inherit from a CLS compliant class like
System::Object.
• Array elements must be CLS compliant.
• See the MSDN for more information.
Fall 2015
CISC/CMPE320 - Prof. McLeod
22
.NET Application Development Realms
• (Or “So, what can you do with it?”)
• Console Applications:
– For developers and admin types, but otherwise extinct.
– If you want simple, low overhead programs that run
fast!
– All you need is a main() and
System::Console.WriteLine().
Fall 2015
CISC/CMPE320 - Prof. McLeod
23
Application Realms, Cont.
• Windows Applications:
– (Languages: VB, C#, C++ and a new one: F#)
– With C++/CLI you use “Windows Forms”, which makes
GUI development as easy as it is in VB.
– Most of the GUI stuff will be in the
System::Windows::Forms namespace.
– Also now supports parallel programming.
– Easy interactions with databases and Office Apps.
Fall 2015
CISC/CMPE320 - Prof. McLeod
24
Application Realms, Cont.
• Web Applications:
– Built using the JScript or the ASP.NET (more
acronyms!!) framework. ASP stands for “Active Server
Pages”. ASP.NET works with VB or C#.
– You can use C++/CLI, but ASP.NET was not designed
to work with C++/CLI directly. To do this you will need
to know enough HTML (“Hyper Text Markup
Language”) and XML (“Extensible Markup Language”)
to build web forms manually.
– Animation Framework – Silverlight (everyone has their
own “Flash” imitation these days…)
Fall 2015
CISC/CMPE320 - Prof. McLeod
25
Application Realms, Cont.
• Windows Services:
– An application that starts when the OS boots up. (Can
also be started manually.)
– No need for user interaction – no interface required.
• Web Services:
– Use a HTTP (“Hyper Text Transfer Protocol”) request to
run a remote application.
– Based on SOAP (“Simple Object Access Protocol”)
which was based on XML.
– Use the System::Services namespace.
– How you deliver “Software As A Service”!! (SAAS!!)
– Supports cloud computing using Windows Azure.
Fall 2015
CISC/CMPE320 - Prof. McLeod
26
Application Realms, Cont.
• Other Platforms (in Studio 2015):
– iOS, Android (using Xamarin and C#, also have C++
cross-platform tools for mobile development, Android
emulator)
– “Universal Windows Apps” for all Windows 10 devices
(Mobile, Tablets, Phone, XBox).
– Windows Store
– HTML, CSS, and JavaScript or Typescript using
Apache Cordova
– VS Tools for Unity game dev (using C#)
– Lightswitch (HTML5 apps without using Silverlight)
– Database development – SQL Server support
Fall 2015
CISC/CMPE320 - Prof. McLeod
27
C++/CLI Integer Types
C++/CLI Alias
Class Library
Description
unsigned char
System::Byte
8 bit unsigned int
char
System::SByte
8 bit signed
short
System::Int16
16 bit signed
unsigned short
System::UInt16 16 bit unsigned
int or long
System::Int32
unsigned int or
long
System::UInt32 32 bit signed
long long or
__int64
System::Int64
32 bit signed
64 bit signed
unsigned long long System::UInt64 64 bit unsigned
Fall 2015
CISC/CMPE320 - Prof. McLeod
28
Integer Type Literals
• The usual stuff:
• char literal in single quotes.
• Append an “L” to get a long literal.
• Prefix with 0x to get a hex literal.
Fall 2015
CISC/CMPE320 - Prof. McLeod
29
C++/CLI Floating Point Types
C++/CLI Alias
Class Library
Description
float
System::Single
32 bit (7 digits)
double
System::Double
64 bit (15 digits)
• Note that there is a long double, but it is no
different from a double in C++/CLI.
Fall 2015
CISC/CMPE320 - Prof. McLeod
30
Extended Precision in C++/CLI
• No traditional C++ equivalent:
System::Decimal
• 128 bits, 28 significant digits.
Fall 2015
CISC/CMPE320 - Prof. McLeod
31
Boolean
• bool
• Class Library is System::Boolean
• true for any non-zero value, false is zero.
• (But don’t use numbers for true and false –
that’s unnecessarily poor style.)
Fall 2015
CISC/CMPE320 - Prof. McLeod
32
Character Type
• wchar_t
• Class Library is System::Char
• A single 16 bit Unicode character.
• Remember char is an 8 bit ASCII character,
Char is a 16 bit Unicode character.
• A unicode literal can look like: '\x0041' to
access non-keyboard characters.
Fall 2015
CISC/CMPE320 - Prof. McLeod
33
C++/CLI Types
• This all means that these types are no longer
“primitive” but are all objects now.
• The C++ names that we are used to are just an
alias to the CLS class name.
• To access the members from a literal, just put ( )
around the value and use the dot operator
(period).
• For example, (123).ToString()->Length
yields 3.
• A variable can be a type or a reference:
Fall 2015
CISC/CMPE320 - Prof. McLeod
34
C++/CLI Handles
• A traditional pointer declaration:
String* pointername;
• or
String *pointer;
• Considered “Unsafe” in C++/CLI. To get a
managed, safe reference variable, use a handle:
String^ handlename;
• or
String ^handlename;
Fall 2015
CISC/CMPE320 - Prof. McLeod
35
Referencing Operators
• The -> operator de-references and obtains
members, as before. Use this on handles.
• The Address of operator, &, is considered unsafe
since it allows the direct manipulation of pointers.
• Instead, use the “Reference” operator, %. This
can be used to obtain references to value and
instances of ref class types, to be stored in a
handle.
• * still acts to de-reference a handle.
Fall 2015
CISC/CMPE320 - Prof. McLeod
36
Aside - Operators
• This Reference operator, %, is the only new
operator symbol in C++/CLI, the rest are all the
same as in ISO C++.
Fall 2015
CISC/CMPE320 - Prof. McLeod
37
Download