EXC_BAD_INSTRUCTION hell

I've been working on a program that generates a melody by means of some intelligent(hopefully) guessing. It compiles nicely, but I get the infamous EXC_BAD_INSTRUCTION error at runtime. I have absolutely no idea where in the code the error could be, so I'm gonna post the code here: http://pastebin.org/153678

The error occurs after scanf has stored the users input.

Hopefully some of you can help me;)


Fafner
#include "Note.cpp"

This always gives me a chill... *brr*..

 
    Note melody[length];


That's a variant array only available in C, not C++. (In C++, all normal arrays on the stack have to have a compile-time constant as its size. "length" is a variable here.)

It shouldn't even compile, should it?

You can use std::vector instead.

Ciao, Imi.
Last edited on
Ah, thanks so much! I come from a C background, so thats why I didnt even think of that. It compiles just fine, which is weird...

Thanks again!
C-guy, eh? Beware that std::vector allocates stuff on the heap. If you are in for uber-performance struggles, you can use _alloca, which is non-standard, but works in C++ as well. ;)

Ciao, Imi.
Thanks, I'll keep that in mind;) I've never used vectors before, so I'm gonna read up now, but it sounds like its what I need.
Last edited on
Topic archived. No new replies allowed.