All,
I am having intermittent problems with my sketch. I've isolated it to a line in my program
mask = N - 1;
for (int index = 0; index < N; index++)
{
if ((index == 0) || (index == N-1))
{
bitflipped = index;
}
else
{
bitflipped = mask & ~index;
}
// this line had a problem until I made a pointer
flippedindex[index] = bitflipped;
}
Earlier in the sketch, the following are defined
unsigned int bitflipped;
unsigned int flippedindex[]={};
unsigned int N=8;
unsigned int mask;
The only way I could get the program to work was to change the "=" to "*="
flippedindex[index] *= bitflipped;
The problem is, I don't know why this worked and the other approach didn't. I've not had luck with the search for this issue.
memotick:
The man in the refrigerator who also runs the compiler?
Both need to be told how big the array is going to be. Either you give a number, or you initial values. Both ways tells the complier how big the array will be.
So as to not start a new thread on a similar topic, where should I put the initialization within a custom library?
I find it has to be within the function it is used in within the library. i.e..
// file mylibrary.cpp
mylibrary::mylibrary(unsigned int N)
{}
void mylibrary::myfunction(unsigned int N) {
unsigned int flippedindex[N];
}
However, I would like to make flipped index an array I can access from the top-level of the library. Should I declare it as a public variable in mylibrary.h?
Sorry if I've botched up the terminology, I'm new to this.
I find it has to be within the function it is used in within the library
Only if you insist on declaring and initializing in one step. You need to either define a pointer, and use malloc to allocate some space (bad idea on a limited memory processor) (be sure to free it in the destructor) OR use a static sized array.
However, I would like to make flipped index an array I can access from the top-level of the library.
Libraries don't have levels. Classes have member fields and methods. If you want to access class member data from outside the class, you should provide methods to do that. The data should almost always be private.