[cfe-dev] @encode objc problem

Fariborz Jahanian fjahanian at apple.com
Sat Mar 7 11:55:51 PST 2009


Behavior should match gcc's.

Please file a bugzilla with a test case.

- fariborz





On Mar 7, 2009, at 10:52 AM, Jean-Daniel Dupas wrote:

> Hello,
>
> I have a question about the behavior of the @encode compiler directive
> in Obj-C.
>
> If we where talking about another language the answer would probably
> be: read the spec, unfortunately, there is not Obj-C spec.
>
> From the Objective-C 2.0 Programming Language:
> 	@encode(type_spec) 	Yields a character string that encodes the type
> structure of type_spec.
>
> http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_950_section_5.html
>
>
> So we could think that the clang implementation is fine, but here come
> the bad news.
>
> Some widely used testing framework (SenTestingKit which is part of the
> Xcode distribution for example) use this kind of test
>
> if (@encode(__typeof__(a1)) != @encode(__typeof__(a2))) {
>
> }
>
> Yep, @encoded "returns" a character string, and these strings are
> compared using == (or != ) and not strcmp, and it works quite well
> using GCC because GCC generates only one const string per type.
>
> As you want that clang be as much compatible as possible with 'GCC', I
> think something should be done about this issue.
>
> And if the Obj-C ref is not updated to guarantee that the returns
> value can be compared using ==, I think you may also add a warning.
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list