2015-05-20 63 views
2

我想在Linux上使用GCC的-fconstant-string-class選項來實現我自己的字符串類。我班的佈局如下GCC無效常量字符串佈局

@interface String : RootObject //my root object class; it is essentially NSObject 
{ 
    char *c_string; 
    unsigned int len; 
} 

這是完全相同的方式GCC tells me to implement this(該isa伊娃從RootObject類繼承),但是當我嘗試使用一個字符串(@"foo"),GCC給我的在編譯時

error: interface String does not have a valid constant string layout 

以下錯誤谷歌搜索給了我this link,但它好像在提問者從來沒有解決他的問題。該類中唯一的另一個ivar是從超類繼承的volatile int retainCount

+0

@JoshCaswell這是問題。刪除伊娃解決了我的問題,所以,如果你願意,你可以發表你的評論作爲答案,我會接受它。 –

+0

甜!答覆已發佈。 –

回答

1

這個retainCount ivar不包含在你引用的規範中。 GNU's Object class doesn't have it,並注意到在Cocoa中,它與GNU的ObjC庫相同的NeXTian起源,-retainCount is part of the NSObjectprotocol,而不是類。

這可能是您的問題,因爲從您的根類繼承它將它放在c_stringlen字段之前,從而導致預期的佈局。

刪除它應該允許這個工作。