Re: returning from within @synchronized results in warnings
Re: returning from within @synchronized results in warnings
- Subject: Re: returning from within @synchronized results in warnings
- From: Jean-Daniel Dupas <email@hidden>
- Date: Wed, 12 Aug 2009 15:24:22 +0200
GCC warns about uninitialized variable, but only on optimized build.
Le 12 août 09 à 15:05, Paul Summermatter a écrit :
Dmitry,
Possibly true. Unfortunately, all my Java experience has led to me
NOT initialize variables like that. The reason being is that Java
IDEs and compilers very nicely warn you if you don't initialize a
variable before its use. As such, this can help catch mistakes that
you might make as in the following:
public void computeValue(BigDecimal input1, BigDecimal input2) {
BigDecimal computedValue;
if (input1.compareTo(input2) == 0) {
computedValue = BigDecimal.valueOf...
}
return computedValue;
}
By not initializing computedValue above, the compiler/IDE will fail/
warn that the value may not be assigned before being returned. This
helps catch the fact that I really needed to have a else block above
to handle the other conditions of computation. If I had initialized
computedValue on the declaration line to be nil or zero or some
other default value, I would lose this check and end up with code
that might fail at runtime.
I'm not sure if Objective-C/gcc/Xcode has any of the same checking,
but I believe it does not.
Paul
On Aug 12, 2009, at 8:51 AM, Dmitry Markman wrote:
does ObjC initialize pointers to NULL?
but in any way
I think it would be better to initialize retval to NULL:
NSString *retval = NULL;
On Aug 12, 2009, at 8:26 AM, Paul Summermatter wrote:
Cem,
I'm a reborn Objective-C'er, but so take my advice as probably
not the most experienced since synchronized was not even available
the last time I used Objective-C. That being said, I would have
expected to see something more like:
- (NSString *)name
{
NSString *retval;
@synchronized (self) {
retval = [[name retain] autorelease];
}
return retval;
}
Also, I thought if you used properties that all of this was done
properly for you under the covers. Unless you have a specific
need to define your own accessor, you might consider just using a
property.
Regards,
Paul
On Aug 12, 2009, at 8:20 AM, Karan, Cem (Civ, ARL/CISD) wrote:
Note that although I mention the iPhone below, this is an Xcode
question, not an iPhone question.
I have a bunch of accessors that I define for properties that are
something like the following:
- (NSString *)name
{
@synchronized(self)
{
return [[name retain] autorelease];
}
}
From what I've read, this is correct Objective-C 2.0 syntax, but
I keep getting compile warnings like the following:
'warning: control reaches end of non-void function'.
This only happens when I'm compiling for the iPhone simulator,
and not for the iPhone itself. Has anyone else seen this? Since
this doesn't happen when I compile to the iPhone, I don't really
care, except that I'm concerned it may affect my testing...
I'm running Xcode 3.1.2, and targetting iPhone OS 2.2.1 if that
helps.
Thanks,
Cem Karan
_______________________________________________
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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
@mac.com
This email sent to email@hidden
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
_______________________________________________
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
_______________________________________________
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