Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2004-08

CFSTR, some C guru please

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Olle Raab
Show quoted text 6 lines
In CFStrings.p compared to CFStrings.h the declaration of CFSTR is simply missing, but many other parts of the UI´s rely on it. So, there is no other way, the following declaration should be added at line 158: function CFSTR(cStr: ConstCStringPtr): CFStringRef; external name '___CFStringMakeConstantString';

OK. It seems to have been a C macro.

But I doesn't understand it completely :

In the C headers, the macros is defined as follows:

#define CFSTR(cStr) __CFStringMakeConstantString(cStr "")

... thus calls:

/* This function is private and should not be used directly */ /*
* __CFStringMakeConstantString()
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.0 and later
* Mac OS X: in version 10.0 or later
*/
EXTERN_API_C( CFStringRef )
__CFStringMakeConstantString(const char * cStr);

In the define there is 2 args, but I see only one param in the function prototype, how come ?

A tip, concerning translation macros: If you cannot do what you did above, you might write a small function which does what the macro did. The function can be made inline, to make it as fast as a macro. (Of course not all macros can be translated to functions)

Olle

BTW Rolf, I divide the discussion in manageble pieces :)

Reply by email

Jonas Maebe
to Olle Raab
Olle Raab wrote 5 lines
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

Reply by email

Dr. Rolf Jansen
to Jonas Maebe
Jonas Maebe wrote 26 lines
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

Reply by email