[cfe-dev] @encode objc problem

Jean-Daniel Dupas devlists at shadowlab.org
Sat Mar 7 10:52:06 PST 2009


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.







More information about the cfe-dev mailing list