dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Type Safe Code

  1. #1
    Join Date
    Jan 2006
    Posts
    384

    Type Safe Code

    Was reading up the book "CLR via C#" and I came across the following statement :

    Code:
    If your assembly files contain only type-safe managed code, you are writing code that should work on both 32-bit and 64-bit versions of Windows. No source code changes are required for your code to run on either version of Windows.
    Can you please elaborate on what is exactly meant by type-safe code (with an example) ?

    Also, how does it ensure that it works OK on both 32-bit and 64-bit processor architectures ?

    Are the rules same when writing native C++ code (unmanaged) too ?

  2. #2
    Join Date
    May 2007
    Posts
    1,546

    Re: Type Safe Code

    I assume it means that you don't use the 'unsafe' keyword (or P/Invokes) in your code nothing you do can make your code dependent on whether or not the underlying operating system is 32 or 64bit. That's all.

    If you use the unsafe keyword and/or P/Invoke native libraries, then you have to worry about 32/64bit issues.
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

  3. #3
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Type Safe Code

    As Mutant_Fruit says, the C# compiler will by default create platform independent assemblies. That's the beauty of .net : The intermediate binary code is just-in-time compiled to the host machine's native architecture when you run the .net application. If that architecture is 64-bit then the program runs as a 64-bit application.
    My hobby projects:
    www.rclsoftware.org.uk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)