“Invalid application of 'sizeof' to interface 'Fraction' in non-fragile ABI” in Objective-C

前端 未结 2 568
刺人心
刺人心 2020-12-12 01:43

I\'m studying Steven Kochan\'s \"Programming in Objective-C 2.0\". We created a Fraction object with two int instance variables. Later in the book Kochan uses the sizeof sta

2条回答
  •  北海茫月
    2020-12-12 01:45

    The object's size could still change because you're using the modern ABI. In older versions of Objective-C, objects were basically structs and that meant it was possible to sizeof() them. This is no longer the case, and it was never a particularly good idea in the first place. I'm not sure what Kochan was trying to teach with it, but FYI this is not necessary to program Objective-C. You should be able to get the old behavior by building as 32-bit on the Mac, but again, that isn't something you'll want to do in real programs.

提交回复
热议问题