A Brief Introduction to C - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

A Brief Introduction to C

Description:

A Brief Introduction to C# David Buksbaum Agenda Goals Background Information C# - Up and Running Quick Comparison to Java Networking Namespaces References Goals ... – PowerPoint PPT presentation

Number of Views:117
Avg rating:3.0/5.0
Slides: 32
Provided by: csNyuEdu2
Learn more at: https://cs.nyu.edu
Category:

less

Transcript and Presenter's Notes

Title: A Brief Introduction to C


1
A Brief Introduction to C
  • David Buksbaum

2
Agenda
  • Goals
  • Background Information
  • C - Up and Running
  • Quick Comparison to Java
  • Networking Namespaces
  • References

3
Goals
  • Provide enough information to allow you to follow
    the code samples
  • Highlight key differences with Java
  • Tell you where you can get the compilers
  • Tell you where to go for more details on C
  • Tell you where to go for more detailed
    comparisons with Java
  • Not to debate which is better, more important,
    faster, slower, or looks better in emacs

4
Quick Glossary
  • BCL Base Class Library
  • CLR Common Language Runtime
  • GUI Graphic User Interface
  • MSIL Microsoft Intermediate Language
  • MS Microsoft
  • SCM Service Control Manager
  • SOA Service Oriented Architecture

5
.NET
  • .NET is
  • Microsofts Platform for Windows Development
  • CLR the Virtual Machine that runs MSIL aka MS
    Byte Code
  • BCL aka .NET Framework
  • A set of compilers that can generate MSIL C,
    Visual Basic, C, Java (the MS flavor)
  • There are 50 languages that generate MSIL
  • http//www.dotnetpowered.com/languages.aspx
  • Most interoperate with each other

6
C
  • Language Created by Anders Hejlsberg (father of
    Delphi)
  • The Derivation History can be viewed here
    http//www.levenez.com/lang/history.html
  • Principle Influencing Languages
  • C
  • Delphi
  • Java
  • Designed to be an optimal Windows development
    language

7
C - Up and Running
  • A Simple C Application
  • Application Types
  • Compiler Run Time

8
A Sample C Application
Code
9
Application Types
  • Console Application
  • Has standard streams (out, in, err)
  • GUI can be added manually
  • Windows Application
  • GUI based
  • No standard streams (out, in, err)
  • Main thread is shared by the GUI message pump
    your code
  • Service
  • No standard streams (out, in, err)
  • Main thread is commandeered by the SCM
  • No GUI

10
Compiler Options from MS
  • SDK contains the command line compiler
    (C\WINDOWS\Microsoft.NET\Framework\version\csc.
    exe)
  • version looks like v2.0.50727
  • Express Edition Free IDE to work with Visual C
  • Reduced runctionality version of Visual Studio
  • Visual Studio The full development system
  • Optimizations, Data Access, Multi-Language, etc

11
Options Beyond MS
  • Mono
  • Open source development SDK for .NET
  • Windows, Linux, Mac OS X, Solaris, Unix
  • Sponsored by Novell
  • Food for thought Suse KDE Mono ???
  • Sharp Develop
  • Open source IDE that uses .NET SDK or Mono
  • Written in C

12
Quick Comparison to Java
  • Whats the same
  • Syntactically Similar
  • Garbage Collected VM Environment
  • Immutable Strings
  • Exceptions (try / catch / finally)
  • Object as root
  • Single Inheritance model
  • Multi-Interface model

13
Whats Different Relevant
  • Keywords
  • base vs. super
  • lock vs. synchronized
  • vs. extends implements
  • is vs. instanceof
  • Exceptions
  • No throws keyword
  • See http//msdn.microsoft.com/chats/transcripts/vs
    tudio/vstudio_032103.aspx

14
Whats Different Relevant cont.
  • Namespaces
  • namespace vs. package
  • using vs. import
  • No wildcard using
  • using namespace // brings it all in
    non-recursive
  • Type Aliasing
  • using newtypename namespace.type
  • Directory structure ! namespace hierarchy (as in
    C)

15
Whats Different Relevant cont.
  • Properties
  • get, set and get/set
  • public string MyProperty get return(_text)
    set _text value
  • Delegates
  • Type safe function pointers
  • To create
  • public delegate bool CompareHandler(object left,
    object right)
  • To use
  • CompareHandler ch new CompareHandler(myMethod)
  • bool retval ch(obj1, obj2)

16
Whats Different Relevant cont.
  • Enumerations
  • public enum Protocol UDP, TCP
  • public enum Direction Up 0, Down 1, Left
    2, Right 4
  • Direction d Direction.Down
  • int x (int)d
  • Direction d Direction.Parse(Up)
  • string s d.ToString()

17
Whats Different Relevant cont.
  • Value Types
  • Primitives are the same plus
  • Unsigned values
  • ubyte, ushort, uint, ulong
  • Careful byte in java is sbyte in C
  • Class objects to wrap primitives
  • Int32 x new Int32(4)
  • int x Int32.Parse(4)

18
Whats Different Relevant cont.
  • Structures
  • Stack based elements, not heap based
  • Value type
  • struct packet int code string data
  • Boxing / Unboxing
  • Conversion between value type and reference type
  • packet p new packet()
  • object o (object)p // boxed
  • packet p2 (packet)o // unboxed
  • Significant performance cost!

19
Whats Different Relevant cont.
  • Cross Platform Support
  • .NET from Microsoft is not cross platform
  • It is for Windows only
  • Mono can run cross platform, but is unproven in
    large production environments
  • MS is currently resisting moving cross platform
  • The future is not set

20
Whats not Relevant, but Useful
  • App Domains
  • One or more per process
  • Represents a VM hosted logical process
  • Communications between App Domains requires
    marshalling (IPC)
  • Assemblies
  • Similar to Java JAR files
  • Physically they are EXE and/or DLL files

21
Whats not Relevant, but Useful
  • Attributes
  • Meta tags that provide run time information for a
    type, NOT the instance
  • Example Serializable public class foo int x
  • Serializable is converted into the class
    SerializableAttribute
  • Attributes can be retrieved at run time
  • Many framework sub-systems use attributes
  • Serialization, XML, Interop, Conditional,
    Obsolete, etc

22
Whats not Relevant, but Useful
  • Polymorphism
  • Methods default to being non-virtual
  • To be virtual it must be defined as virtual
  • eg public virtual int Add(int x, int y)
  • To override a virtual method, you use the
    override keyword
  • eg. public override int Add(int x, int y)
  • Methods not marked virtual are equivalent to Java
    final methods
  • Methods can be marked with new to break the
    virtual chain

23
Whats not Relevant, but Useful
  • Interop
  • Access to native code through attributes
  • DllImport(user32.dll) static int
    GetSystemMetrics(int)
  • The DllImport attribute informs the compiler and
    runtime that the tagged method is inside a native
    DLL.
  • Options such as the actual name in the DLL,
    marshalling strategies, calling convention, and
    more can be set using the attribute

24
Whats not Relevant, but Useful
  • .NET 2.0 out now
  • Generics
  • Partial Types
  • Anonymous Methods
  • Nullable Types
  • .Net 3.0
  • Its all about data
  • Tuples Query constructs
  • public void Linq1()
  • int numbers 5, 4, 1, 3, 9, 8, 6, 7, 2, 0
  • var lowNums from n in numbers where n lt 5
    select n
  • Console.WriteLine("Numbers lt 5")
  • foreach (var x in lowNums) Console.WriteLine(x)
  • ResultNumbers lt 541320

25
Networking Namespaces
  • System.Messaging
  • Functionality for MSMQ
  • System.Net
  • Provides access to higher protocols (FTP, HTTP,
    DNS)
  • System.Net.Information
  • Network information classes providing statistics,
    interface information, and ping
  • System.Net.Sockets
  • Light weight wrappers around TCP and UDP sockets
  • System.Runtime.Remoting
  • Provides functionality for high level distributed
    programming (similar to RMI)
  • System.Web
  • Provides high level access to HTTP

26
Future of .NET Networking
  • Windows Communications Foundation
  • Formally code named Indigo
  • Designed to make SOA an integral part of Windows
  • Tight coupling with .NET designs
  • For more information
  • http//msdn.microsoft.com/windowsvista/default.asp
    x?pull/library/en-us/dnlong/html/wcfarch.asp

27
References
28
Links
  • .NET SDK
  • http//www.microsoft.com/downloads/details.aspx?Fa
    milyIDfe6f2099-b7b4-4f47-a244-c96d69c35decDispla
    yLangen
  • MS Visual Studio C Express Edition
  • http//msdn.microsoft.com/vstudio/express/visualcs
    harp/
  • MS Visual Studio
  • http//msdn.microsoft.com/vstudio/

29
Links cont.
  • MONO
  • http//www.mono-project.com/Main_Page
  • Sharp Develop
  • http//www.icsharpcode.net/OpenSource/SD/

30
Links cont.
  • C Links
  • http//msdn1.microsoft.com/en-us/default.aspx
  • http//gotdotnet.com/
  • http//www.c-sharpcorner.com/
  • http//msdn.microsoft.com/community/codezone/
  • http//en.wikipedia.org/wiki/C_Sharp_programming_l
    anguage
  • Online Tutorials
  • http//www.csharp-station.com/Tutorial.aspx
  • http//www.c-sharpcorner.com/Tutorials.asp

31
Books
  • Programming C, Fourth Edition by Jesse Liberty
    (http//search.barnesandnoble.com/booksearch/isbnI
    nquiry.asp?zyisbn0596006993itm2)
  • CLR Via C Applied Microsoft .Net Framework 2.0
    Programming by Jeffrey Richter (http//search.barn
    esandnoble.com/booksearch/isbnInquiry.asp?zyisbn
    0735621632itm3)
Write a Comment
User Comments (0)
About PowerShow.com