我试图将两个变量传递给方法,但得到一个断点:线程错误

时间:2013-06-01 09:45:48

标签: ios objective-c

以下是代码:

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

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        int a,b,sum,mul1,mul2;
        microsoft *m1=[microsoft alloc];
        NSLog(@"\nEnter first variable : ");
        scanf("%d",&a);
        NSLog(@"\nEnter first variable : ");
        scanf("%d",&b);
        [m1 sumvar1:a var2:b];
        sum=[m1 getsum];

        mul1=[m1 mulvar1:3 var2:3]; // Error Line -----
        mul2=[m1 getmul];         

        [m1 name:@"hello"];

        NSLog(@"\nName : %@ \n Sum = %d \n Mul = %d",[m1 name],sum,mul1);
    }
    return 0;
}

DEBUG NAVIGATOR - 线程1

libdyld.dylib`start:
0x7fff91f6d7e1:  movl   %eax, %edi
0x7fff91f6d7e3:  callq  0x7fff91f6d808            ; symbol stub for: exit
0x7fff91f6d7e8:  hlt    

DEBUG NAVIGATOR - 线程2

libsystem_kernel.dylib`kevent:
0x7fff9427ad0c:  movl   $33554795, %eax
0x7fff9427ad11:  movq   %rcx, %r10
0x7fff9427ad14:  syscall
0x7fff9427ad16:  jae    0x7fff9427ad1d            ; kevent + 17
0x7fff9427ad18:  jmpq   0x7fff9427b4d4            ; cerror_nocancel
0x7fff9427ad1d:  ret    
0x7fff9427ad1e:  nop    
0x7fff9427ad1f:  nop    

为什么此声明mul1=[m1 mulvar1:3 var2:3]导致崩溃?

1 个答案:

答案 0 :(得分:2)

您的microsoft实例似乎未初始化:alloc的调用给出了实例内存,但没有设置实例本身。在创建alloc的调用中将new替换为m1,如下所示:

microsoft *m1=[microsoft new];