Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8568149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:02:40+00:00 2026-06-11T18:02:40+00:00

I’m converting some Objective-C code to ARC that makes heavy use of the GCC

  • 0

I’m converting some Objective-C code to ARC that makes heavy use of the GCC “Statements and Declarations in Expressions” extension ({}).

The GCC extension is being used in preprocessor macros to create Objective-C objects. The actual macros are fairly complex, so here is a contrived example to simplify things. Assume for the purposes of my example that the _x parameter is always NSString *:

#define f(_x) ({ NSString *x = (_x); [NSString stringWithString: x]; })

This macro would of course be called like so:

void foo() { NSString *s = f(@"foo"); }

In the pre-ARC environment this works just fine. The object created by the stringWithString: call is an autoreleased object and the GCC extension assigns it to s.

After converting to ARC (Xcode 4.4.1) however the object is released immediately when the statement block exits (I confirmed this by instantiating an object that NSLog()s it’s dealloc).

I’ve tried modifying the macro with typecasts like:

#define f(_x) ({ NSString *x = (_x); (__autoreleasing id) [NSString stringWithString: x]; })

and

#define f(_x) ({ NSString *x = (_x); (NSString __autoreleasing *) [NSString stringWithString: x]; })

but both forms result in a compilation error:

Explicit ownership qualifier on cast has no effect

It appears then that ARC and this GCC extension are incompatible.

Is this so or am I missing something simple that tells ARC not to immediately release the object?

I do have some options, the most attractive of which at the moment seems to be to convert all of these macros to __inline__ functions but I have quite a bit of code to deal with. I’m really hoping for a quick fix so any ideas are appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:02:41+00:00Added an answer on June 11, 2026 at 6:02 pm

    I’ve been debugging this for a few hours now and found a solution so I’ll answer my own question. FWIW I agree with CRD and think it’s a bug–I’ll file a report with Apple.

    It happens that the “contrived example” I made up for my question actually works (doh). As I mentioned originally the macros I’m working with are much more complicated and they don’t. I’ve discovered though that they will if I return the created object through a temporary as the last statement in the statement block. When written like that ARC doesn’t release the object. I assume there’s some very narrow RVO-type code in clang and it’s colliding with the ARC parser.

    At any rate, the workaround looks this (scroll to the very end of the line):

    #define f(_x) ({ NSString *x = (_x); NSString *y = [NSString stringWithString: x]; y; })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.