• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: returning from within @synchronized results in warnings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: returning from within @synchronized results in warnings


  • Subject: Re: returning from within @synchronized results in warnings
  • From: Dmitry Markman <email@hidden>
  • Date: Wed, 12 Aug 2009 09:14:23 -0400


in that particular case you're right

but it should be a habit to initialize variable, here is why:

	suppose you have the method

	A *getA()
	{
		A *err; //err is a pointer to some error object
			if(some_condition) {
				err = foo(.......);
			}

		return err;

	}


another programmer decided to throw exception in foo, so new code will be


	A *getA()
	{
		A *err; //err is a pointer to some error object
			try {
				foo(.......);
			} catch (E &e) {
				err = createA(e);
			}

		return err;

	}

as you can see if foo doesn't throw exception pointer a will be returned not initialized


On Aug 12, 2009, at 9:02 AM, Ken Thomases wrote:

On Aug 12, 2009, at 7:51 AM, Dmitry Markman wrote:

does ObjC initialize pointers to NULL?

No, it doesn't. It matches C in this respect.

but in any way
I think it would be better to initialize retval to NULL:

NSString *retval = NULL;

Why? It's immediately and unconditionally followed by an assignment. There's little reason to initialize the variable directly above the assignment.


Regards,
Ken


Dmitry Markman

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >returning from within @synchronized results in warnings (From: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>)
 >Re: returning from within @synchronized results in warnings (From: Paul Summermatter <email@hidden>)
 >Re: returning from within @synchronized results in warnings (From: Dmitry Markman <email@hidden>)
 >Re: returning from within @synchronized results in warnings (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: returning from within @synchronized results in warnings
  • Next by Date: Re: returning from within @synchronized results in warnings
  • Previous by thread: Re: returning from within @synchronized results in warnings
  • Next by thread: Re: returning from within @synchronized results in warnings
  • Index(es):
    • Date
    • Thread