  * C code.  This is because we modify a copy of the structure 
  * populated by the C code.
  */
-let OneWayCallback : my_cb_t = {( p : UnsafeMutablePointer<Void> )->Void in
+let OneWayCallback : my_cb_t = {( p : UnsafeMutableRawPointer? )->Void in
     print( "In OneWayCallback(), received a void pointer. " );
-    var _apiS : APIStruct = (UnsafeMutablePointer<APIStruct>(p)).memory
+    // Could have used unsafeBitCast() here
+    guard var _apiS = p?.assumingMemoryBound(to: APIStruct.self).pointee else {
+        print("Could not dereference APIStruct pointer.")
+        return
+    }
     printAPI ( _apiS );
-    print( "Setting m_Long in the structure to 98765432109 " )
+    print( "Setting m_Long in the structure to 98765432109" )
     _apiS.m_Long = 98765432109
 }
 

/**
 * A better callback implementation.
 *
 * This one casts the void pointer to UnsafeMutablePointer<APIStruct>,
 * then uses its memory to construct an instance of APIStruct.  Even if
 * tight packing is used by the C code, the APIStruct will correctly 
 * reflect the data placed there by the C code.  This is as long as 

//  main.swift
//  callback_void
//
//  Created by Anatoli on 11/5/2015.
//  Updated for Swift 3 on 11/14/2016.
//  Copyright © 2015 Anatoli Peredera. All rights reserved.
//

