[fpc-devel]CFSTR, some C guru please

Dr. Rolf Jansen InstantWare at t-online.de
Mon Aug 16 14:17:54 CEST 2004


Am 16.08.2004 um 13:18 schrieb Jonas Maebe:

>
> On 16 aug 2004, at 13:05, Olle Raab wrote:
>
>> But I doesn't understand it completely :
>>
>> In the C headers, the macros is defined as follows:
>>
>> #define CFSTR(cStr) __CFStringMakeConstantString(cStr "")
>
> In the CFString.h of the CoreFoundation framework it's defined as
>
> #define CFSTR(cStr)  __CFStringMakeConstantString("" cStr "")
>
> but that doesn't really matter.
>
> "" is the same as '' in Pascal: it's an empty string. In C, to 
> concatenate constant string, you don't put a "+" in between them, you 
> just write them next to each other. So In Pascal that would be
>
> __CFStringMakeConstantString('' + cStr + '');
>
> This is probably to force some typecasting for certain ambiguous 
> C-constructs. Pascal shouldn't need this.
>
>
> Jonas

I would like to add only that the CFSTR routine when declared as 
follows:

   function CFSTR(cStr: ConstCStringPtr): CFStringRef;
        external name '___CFStringMakeConstantString';

does really work and gives correct results when called from a Free 
Pascal program on OS X.

Please note the three undersores. Please note also that for this to 
work, ConstCStringPtr has to be declared as PChar in MacTypes.p.

In Free Pascal this is so much more elegant compared to the macro in C, 
isnĀ“t it?

Rolf





More information about the fpc-devel mailing list