const-str-13.mm

来自「Mac OS X 10.4.9 for x86 Source Code gcc」· MM 代码 · 共 45 行

MM
45
字号
/* APPLE LOCAL file 4080358 *//* Test if ObjC strings play nice with -fwritable-strings.  *//* Author: Ziemowit Laski  *//* { dg-options "-fno-constant-cfstrings -fwritable-strings -fconstant-string-class=Foo" } *//* { dg-do run { target *-*-darwin* } } */#include <objc/Object.h>#include <stdlib.h>#include <memory.h>@interface Foo: Object {  char *cString;  unsigned int len;}- (char *)c_string;@endstruct objc_class _FooClassReference;static Foo *foobar = @"Apple";@implementation Foo- (char *)c_string {  return cString;}@endint main(void) {  char *c, *d;  /* Initialize the metaclass.  */  memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference));  c = [foobar c_string];  d = [@"Hello" c_string];  if (*c != 'A')    abort ();  if (*d != 'H')    abort ();  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?