<div dir="ltr">What’s the Swift type signature on GDALOpen? My guess is that it’s returning a UnsafePointer<Void> or UnsafeMutablePointer<Void> type. Swift doesn’t currently handle nullability for C pointers (hence the “Unsafe” prefix). You’ll need to check the value at the pointer’s location manually.<div><br></div><div>Dan</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 1, 2016 at 2:59 AM, Rick Mann via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have some Swift code (in Xcode 7.3) that's calling a C function in the GDAL library. It's declared like this:<br>
<br>
typedef void *GDALDatasetH;<br>
GDALDatasetH CPL_DLL CPL_STDCALL<br>
GDALOpen( const char *pszFilename, GDALAccess eAccess ) CPL_WARN_UNUSED_RESULT;<br>
<br>
I'm calling it with code like this:<br>
<br>
class<br>
MyClass<br>
{<br>
func foo()<br>
{<br>
self.dataset = GDALOpen(path, GA_ReadOnly)<br>
}<br>
<br>
var dataset: GDALDatasetH?<br>
}<br>
<br>
But later code<br>
<br>
if let ds = self.dataset<br>
{<br>
print("dataset: \(ds)")<br>
}<br>
<br>
outputs this to the console:<br>
<br>
dataset: 0x0000000000000000<br>
<br>
This seems very broken.<br>
<span><font color="#888888"><br>
--<br>
Rick Mann<br>
<a href="mailto:rmann@latencyzero.com" target="_blank">rmann@latencyzero.com</a><br>
<br>
<br>
_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</font></span></blockquote></div><br></div></div>