Interrupts fail on a mega when I create an int8_t variable in loop()?????

Has any one encountered this sort of bizarre run time error.

I can trigger my ISR routines quite happily, with a wire connecting mega's 5V pin to GNDed pins 2 and 3, until I place any int8_t variable in my loop function.

I can uncomment all the other variables at the top of my loop function and interrupts work just fine, so it can't be a stack overflow problem.

But If there is one single int8_t variable, with our without any other variables, then interrupts no longer work.

Does anyone have an explanation for this?

void loop() 
{
String strCmd;
//	int8_t nPin = 0, nVal1 = 0, nVal2 = 0, nVal3 = 0, nVal4 = 0;
        int8_t nPin = 0;
	//int16_t nVal = 0;
        //uint8_t nI = 0;
        //char cCmd = 0, cBank = 0;
        //bool bVal = false;
	//void (* pointerISR)() = NULL;
#include <Wire.h>
#include <MCP23017.h>
#include <string.h>

CMCP23017 mcp;

volatile uint8_t nPin = 0;
uint8_t nLEDISR1 = 10, nLEDISR2 = 11;

void ISR1()
{
  noInterrupts();
  nPin = nLEDISR1;
}

void ISR2()
{
  noInterrupts();
  nPin = nLEDISR2;
}

void printHelp()
{
  Serial.println(F("*********************************************************************************************************************************************************************************************"));
  Serial.println(F("*"));
  Serial.println(F("* MCP23017 library testing sketch"));
  Serial.println(F("* ==============================="));
  Serial.println(F("* 'a' or 'A'[0, 1 (if 0 register auto-increment off, if 1 register auto-increment on)] = trun register auto-increment on and off..."));
  Serial.println(F("* 'b' or 'B'[0, 1 (if 0 registers in single bank, if 1 registers in seperate banks)] = set single of seperate register banks..."));
  Serial.println(F("* 'c' or 'C' = clear interrupts..."));
  Serial.println(F("* 'i' or 'I'[0 -> 15]' = set pin as input..."));
  Serial.println(F("* 'o' or 'O' [0 -> 15]' = set pin as output..."));
  Serial.println(F("* 'p' or 'P'[0 -> 15],[0, 1 (if 0 then pullup resistor is removed from pin, if 1 then pullup resistor is added to pin)]' = add pullup resistor to pin..."));
  Serial.println(F("* 'w[0 -> 15],[0, 1]' = write to an individual pin..."));
  Serial.println(F("* 'r[0 -> 15]' = read an individual pin..."));
  Serial.println(F("* 'W[0 -> 15],[binary 16 bit integer with each bit representing the new state for each pin]' = write to all pins..."));
  Serial.println(F("* 'R[0 -> 15]' = read all pins..."));
  Serial.println(F("* 'x' or 'X'[1, 0 (interrupt pin high)],[1, 0 (interrupt pins mirror each other)],[1, 0 (interrupt pins open drain)] = set interrupt behavior..."));
  Serial.println(F("* 'y' or 'Y'[0 -> 15 (pin number)],[0, 1 (if 0 then LOW when triggered, if 1 then HIGH when triggered)],"));
  Serial.println(F("*           [0,1 (arduino interrupt number - if 0 then arduino pin 10 goes HIGH briefly, if 1 then arduino pin 11 goes HIGH briefly)],"));
  Serial.println(F("*"));
  Serial.println(F("*********************************************************************************************************************************************************************************************"));
}

int8_t parseInt(const char* strCmd, uint8_t& nI)
{
	String strNum;
	int8_t nInt = -1;

	for (nI = nI; nI < strlen(strCmd); nI++)
	{
		if ((strCmd[nI] >= '0') && (strCmd[nI] <= '9'))
		{
			strNum += strCmd[nI];
		}
		else
			break;
	}
                
	if (strNum.length() > 0)
		nInt = strNum.toInt();
	else
		nInt = -1;

	return nInt;
}

int16_t parseBinaryInt(const char* strCmd, uint8_t& nI)
{
	String strNum;
	int16_t nInt = -1, nMult = 1;
	uint8_t nJ = 0;

	for (nI = nI; nI < strlen(strCmd); nI++)
	{
		if ((strCmd[nI] >= '0') && (strCmd[nI] <= '9'))
		{
			strNum += strCmd[nI];
		}
		else
			break;
	}
                
	if (strNum.length() > 0)
	{
		for (nJ = strNum.length() - 1; nJ >= 0; nJ--, nMult *= 2)
		{
			nInt += ((uint8_t)strNum[nJ] - (uint8_t)'0') * nMult;
		}
	}
	else
		nInt = -1;

	return nInt;
}

bool isValidPin(const int8_t nPin)
{
	bool bValid = (nPin >= 0) && (nPin <= 15);

	return bValid;
}

bool isValidBool(const int8_t nVal)
{
	bool bValid = (nVal == 0) || (nVal == 1);

	return bValid;
}

const char* removeWhiteSpace(const char* strCmd)
{
	uint8_t nI = 0, nJ = 0;
	static String strTmp;

        strTmp = "";
	for (nI = 0; nI < strlen(strCmd); nI++)
	{
		if ((strCmd[nI] >= ' ') && (strCmd[nI] <= '~'))
			strTmp += strCmd[nI];
	}
	return strTmp.c_str();
}

void printCommandConfirm_(String& strCmd, const uint8_t nI, const char* strVal)
{
  Serial.print(F("'"));
  Serial.print(strCmd.substring(0, nI));
  Serial.print(F("' - "));
  Serial.print(strVal);
  Serial.println(F("'..."));
}

void printCommandConfirm(String& strCmd, const uint8_t nI)
{
  Serial.print(F("'"));
  Serial.print(strCmd.substring(0, nI));
  Serial.println(F("' - done..."));
}

void printInvalidCmdMsg(String& strCmd, const uint8_t nI)
{
  Serial.print(F("'"));
  Serial.print(strCmd.substring(0, nI));
  Serial.println(F("' is an invalid command..."));
  printHelp();
}

void setup() 
{
  Serial.begin(115200);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(nLEDISR1, OUTPUT);
  pinMode(nLEDISR2, OUTPUT);
  
  noInterrupts();
  attachInterrupt(0, ISR1, RISING);
  attachInterrupt(1, ISR2, RISING);
  interrupts();
}

void loop() 
{
	String strCmd;
//	int8_t nPin = 0, nVal1 = 0, nVal2 = 0, nVal3 = 0, nVal4 = 0;
        int8_t nPin = 0;
	//int16_t nVal = 0;
        //uint8_t nI = 0;
        //char cCmd = 0, cBank = 0;
        //bool bVal = false;
	//void (* pointerISR)() = NULL;

	if (nPin > 0)
	{
                digitalWrite(nPin, HIGH);
		delay(200);
		digitalWrite(nPin, LOW);
		if (nPin == nLEDISR1)
			Serial.println(F("Interrupt 1 generated..."));
		else if (nPin == nLEDISR2)
			Serial.println(F("Interrupt 2 generated..."));
        nPin = 0;
              interrupts();
	}

}

Correction...

It is not int8_t that is causing interrupts to fail but rather the fact that I call the variable nPin.

As long as I rename nPin to something else then interrupts trigger fine.

It still makes absolutely no sense!

Two variables called nPin == Recipe for confusion.

BTW, your diagnosis is incorrect - in both cases, interrupts trigger perfectly well.

AWOL:
Two variables called nPin == Recipe for confusion.

BTW, your diagnosis is incorrect - in both cases, interrupts trigger perfectly well.

Yeah I eventually spotted it. There was probably a compiler warning but no error.

So my loop code was accessing the local which means that interrupts() was never called after they were disabled by the ISR itself....and the LED never flashed.

void ISR1()
{
  noInterrupts();

Interrupts are already disabled when an interrupt service routine is called.

  noInterrupts();
  attachInterrupt(0, ISR1, RISING);
  attachInterrupt(1, ISR2, RISING);
  interrupts();

There is no need to disable interrupts to attach interrupt handlers.