-1

First time asking a question here, but I'm really confused by this. This is essentially what I'm trying to do:

- (MyStruct)methodName:(OtherStruct)foo
{
    MyStruct bar;
    memcpy(&bar, &foo, sizeof(MyStruct));
    return bar;
}

My attempts to figure this out have gotten me this info:

  • sizeof(bar) == 64
  • sizeof(foo) == 80
  • sizeof(MyStruct) == 64
  • sizeof(OtherStruct) == 80

I get EXC_BAD_ACCESS (code=1, address=0x0). Am I missing something silly?

Tyler
  • 13
  • 3

1 Answers1

0

What EXC_BAD_ACCESS is saying is that you did something that caused a pointer to be dereferenced and that memory location isn’t inside one of the chunks assigned to your program, so it is an MMU problem.

Onur Turhan
  • 1,237
  • 1
  • 13
  • 20
  • Doesn't the third argument of memcpy limit the number of bytes copied? The struct I'm copying to has the same members as the struct I'm copying from, so I'm just grabbing those. – Tyler Mar 18 '13 at 00:52
  • Oh I found the problem! The problem was that I was assigning the return value of this method to a de-referenced pointer. I just saw memcpy and the method call in the error and assumed it was there. Thanks for the help! – Tyler Mar 18 '13 at 00:56