Getting errors when using pointers... plz help

Hey everyone,

Just started using pointers :slight_smile: , here is my code which is getting an error I will display after.

This is a global function I have created which causes the error:

void mk7sixt() {
  if (sMode == 1 && m_sys == 1 && m_vs1 == 0) {pBit = &m_sixt1;}

However the compiler says the error happens when it is called in the Setup() area here:

     byteVal = 0;                          
      for (int i=3; i>=0; i--) {              
      bitWrite(byteVal, i, shiftdata0[i]);
      if (i == 0) {
        svalueI = fourPos(byteVal);
          paramList[3] = svalueI;

          if (syAorM == 1) {
            mk7sixt();             //<-- THIS IS WHERE THE FUNCTION IS CALLED (line 422)
            bitClear(*pBit, 3);
            if(svalueI == 0) {
            } else {                                      
              bitSet(*pBit, 3);


And here is the error:

sketch\C-MKS7-d-July5.ino.cpp.o: In function setup':** **C:\Users\dmorr\Documents\arudino projekts\C-MKS7-d-July5/Setup.ino:422:(.text.setup+0xd5a): relocation truncated to fit: R_AVR_7_PCREL against no symbol’
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board ATmega1284.

The goal of this mk7sixt() function is to simply change the address of the pointer pBit so the bitclear/bitset operations execute on different variables, depending on those conditions. You might be wondering why I am calling a function with only one if-statement, well there were lots of if-statements in the function originally, but even with just one if-statement I still get this error, so something about the way of assigning this pointer an address is causing problems (i think?? :confused: ), but I have no idea why. All variables are byte types and all variables are global, so there shouldn’t be any scope issues… Any insight would be greatly greatly appreciate, thank you!

Okay I think the solution here is possibly you cannot always fit the address of some memory location into the byte type variable, you need to use int.

Where’s the definition for pBit?
You can’t have a pointer to a bit for a start, if that’s what you are trying to do.

sorry that variable name is confusing, it was meant to be pByte and the variable definition was:

byte *pBit;

But I switched the variables to be integers instead of bytes and now things are compiling, I’ll test it tomorrow but that seams to have solved it.