• 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
EXC_BAD_ACCESS on returning an int?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

EXC_BAD_ACCESS on returning an int?


  • Subject: EXC_BAD_ACCESS on returning an int?
  • From: Ian Havelock <email@hidden>
  • Date: Sun, 5 Jul 2009 01:39:09 +0100

Hi All,

I've just started to learn my way around Cocoa but I've come across an error message that I don't understand and googling hasn't really shed any light on the subject.

I have defined a simple polygon class with 3 int's, called PolygonShape. When debugging I can see that I am setting the properties correctly, but when I try to output the object's variables using NSLog I receive an EXC_BAD_ACCESS error?

When it hits the NSLog line in 'PolygonShape Testing.m', it goes through (from the right) returning maximumNumberOfSides, minimumNumberOfSides and numberOfSides, but when it hits the closing } after return numberOfSides I get the EXC_BAD_ACCESS error?

As I'm using int's and not string Objects such as NSString I don't see how it could be memory management related unless there is something I'm missing?


Running… Program received signal: “EXC_BAD_ACCESS”. (gdb)




I apologise for posting such a lengthy email.




// PolygonShape.h

#import <Cocoa/Cocoa.h>

@interface PolygonShape : NSObject

{
	int numberOfSides;
	int minimumNumberOfSides;
	int maximumNumberOfSides;
}

@property int numberOfSides;
@property int minimumNumberOfSides;
@property int maximumNumberOfSides;


- (int)numberOfSides; - (void)setNumberOfSides:(int)numberOfSides;

- (int)minimumNumberOfSides;
- (void)setMinimumNumberOfSides:(int)minimumNumberOfSides;

- (int)maximumNumberOfSides;
- (void)setMaximumNumberOfSides:(int)maximumNumberOfSides;

@end







// PolygonShape.m


#import "PolygonShape.h"


@implementation PolygonShape

@synthesize numberOfSides;
@synthesize minimumNumberOfSides;
@synthesize maximumNumberOfSides;


- (int)numberOfSides { return numberOfSides; }

- (void)setNumberOfSides:(int)value {
		numberOfSides = value;
}


- (int)minimumNumberOfSides { return minimumNumberOfSides; }

- (void)setMinimumNumberOfSides:(int)value {
	minimumNumberOfSides = value;
}


- (int)maximumNumberOfSides { return maximumNumberOfSides; }

- (void)setMaximumNumberOfSides:(int)value {
	maximumNumberOfSides = value;
}

@end










// PolygonShape Testing.m

#import <Foundation/Foundation.h>
#import "PolygonShape.h"


void PrintPolygonInfo() { PolygonShape *poly1 = [[PolygonShape alloc] init];

[poly1 setMinimumNumberOfSides:3];
[poly1 setMaximumNumberOfSides:12];
[poly1 setNumberOfSides:6];

NSLog(@"Number of Sides: %@, Min: %@, Max: %@", [poly1 numberOfSides], [poly1 minimumNumberOfSides], [poly1 maximumNumberOfSides]);


}


int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; PrintPolygonInfo();

    [pool drain];
    return 0;
}






Many Thanks, Ian_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: EXC_BAD_ACCESS on returning an int?
      • From: Andrew Farmer <email@hidden>
    • Re: EXC_BAD_ACCESS on returning an int?
      • From: mmalc Crawford <email@hidden>
    • Re: EXC_BAD_ACCESS on returning an int?
      • From: Andrew Merenbach <email@hidden>
  • Prev by Date: Re: Yet another memory management question
  • Next by Date: [modeator] Re: leaking UIColor objects
  • Previous by thread: Re: Yet another memory management question
  • Next by thread: Re: EXC_BAD_ACCESS on returning an int?
  • Index(es):
    • Date
    • Thread