test.h
-------
struct session {
int a;
int c;
int b;
};
struct session* pEvent;
#import <Foundation/Foundation.h>
@interface test : NSObject {
}
-(void)set;
@end
test.m
--------
#import "test.h"
@implementation test
-(id)init{
pEvent->a=10;
pEvent->c='a';
pEvent->b=20;
return self;
}
-(void)set{
//struct session* pEvent;
//pEvent->a=10;
//pEvent->c='a';
//pEvent->b=20;
NSLog(@"a:%d c:%c b:%d",pEvent->a,pEvent->c,pEvent->b);
}
@end
I am getting EXC_BAD_ACCESS runtime exception and the debugger points to pEvent->a when
declared in both the ways inside the init method or inside the set method.
Do i need to intialise the structure as pEvent = new session;? If declared like this I’m
getting new undeclared error. Then I tried with pEvent = [session new]; and pEvent = [[session alloc]init]; If declared like this i’m getting session undeclared error.
Try this:
You got bad access as you have not allocated memory for
pEvent, just declared a pointer.