Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>there's no obvious point in doing this. a c style cast is not like other languages - it is a typecast which the address on the left will be identical to the address on the right. cftypes will not throw or return null if you do a bad cast (unlike other languages). iow, it's merely a decoration for you to specify a type, and a c compiler will assume your cast is valid.</p> <p>or perhaps you can provide a better example of how you would use this, if that did not help.</p> <p><strong>Update</strong></p> <p>ok. since you tagged it objc++, i'd just create a helper class which had plenty of diagnostics and did all the noisy conversions (minimal illustration):</p> <pre><code>class t_helper { public: t_helper(CFTypeRef cf) : d_cf(cf), d_type(CFGetTypeID(cf)) { assert(this-&gt;d_cf); } ~t_helper() {} /* type info */ bool isString() const { return CFStringGetTypeID() == this-&gt;type(); } CFStringRef string() { assert(this-&gt;isString()); return this-&gt;cf_cast&lt;CFStringRef&gt;(); } bool isDictionary() const { return CFDictionaryGetTypeID() == this-&gt;type(); } CFDictionaryRef dictionary() { assert(this-&gt;isDictionary()); return this-&gt;cf_cast&lt;CFDictionaryRef&gt;(); } ... /* and a trivial example of an operation */ void appendMutableCopyToArray(CFMutableArrayRef array) { if (this-&gt;isString()) { CFMutableStringRef cp(CFStringCreateMutableCopy(0,0,this-&gt;string())); CFArrayAppendValue(array, cp); CFRelease(cp); } ... } ... private: template &lt; typename T &gt; T cf_cast() { return reinterpret_cast&lt;T&gt;(this-&gt;d_cf); } const CFTypeID type() const { return this-&gt;d_type; } private: CFTypeRef d_cf; const CFTypeID d_type; }; </code></pre> <p>that's about as accurate as i can get get without a really specific example of the program you are dealing with.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload