I took this code verbatim out of the CFPreferences docs:
int dropMethod = 0;
CFStringRef dropMethodKey = CFSTR("dropMethod");
CFNumberRef dropMethodVal = CFPreferencesCopyAppValue(dropMethodKey,
kCFPreferencesCurrentApplication);
if (dropMethodVal)
{
if (!CFNumberGetValue(dropMethodVal, kCFNumberIntType,
&dropMethod))
dropMethod = 0;
CFRelease(dropMethodVal);
}
else dropMethod = 0;
I get a warning on the third line (assignment to dropMethodVal). The
warning is:
Invalid conversion from 'const void*' to 'const __CFNumber*'
Like I said, this is practically verbatim from the dos. The application
runs fine. It saves and retrieves preferences without any trouble after
multiple app launches. I just don't understand why I'm getting warning
for code from the docs. Is it actually wrong? Should I just put a cast
in front of it to get rid of the warning even thought the docs didn't use
a cast?
Thanks.
________________________________________________________________________
Keith Wiley kwiley@cs.unm.edu http://www.unm.edu/~keithw
"Yet mark his perfect self-contentment, and hence learn his lesson,
that to be self-contented is to be vile and ignorant, and that to
aspire is better than to be blindly and impotently happy."
-- Edwin A. Abbott, Flatland
________________________________________________________________________
Eric Albert - 16 Aug 2005 19:09 GMT
> I took this code verbatim out of the CFPreferences docs:
>
[quoted text clipped - 22 lines]
> in front of it to get rid of the warning even thought the docs didn't use
> a cast?
Yep...CFPreferencesCopyAppValue returns a CFPropertyListRef, which is a
CFTypeRef, which is a const void *. In C++ (I think), you can't
implicitly convert from a void * to another pointer type. You have to
cast the return value to the right type.
So yeah, add a cast to CFNumberRef and file a bug against the
documentation.
-Eric

Signature
Eric Albert ejalbert@cs.stanford.edu
http://outofcheese.org/