Suspected flash replication on pointer code use.

I have code under construction that I’m trying to use a class object for.

I’m doing something wrong, but don’t remember how this can happen.

I can compile the so-far for Mega but not Uno once the class object gets compiled in. The thing is that I tried to use nothing but pointers to tables in PROGMEM but it (only) SEEMS that somehow I’m telling the compiler to make copies of those.

If I can get an answer in the next few hours then I’ll try to do this “with Class” otherwise not since that fit in code that didn’t.

Out on a limb and can’t remember how to get back this time…

// Under Construction
// Dictionary_Object_w_branch_table.ino ver 1.0 by GoForSmoke @ Arduino Forum
// Free for use, Apr 30th, 2016
//
// Put the example and library files in the project folder.

#include <avr/io.h>
#include <avr/pgmspace.h>
#include "dictionary_w_branch.h"

 findMatch myList;

// this is a data set that gets referred to when a match is made.
// it is just for demonstration value.
const byte keys = 16;
const byte keylen = 8;

const char key00[] PROGMEM  = "memccpy"; 
const char key01[] PROGMEM  = "memchr";
const char key02[] PROGMEM  = "memcmp";
const char key03[] PROGMEM  = "memcpy";
const char key04[] PROGMEM  = "memmem";
const char key05[] PROGMEM  = "memmove";
const char key06[] PROGMEM  = "memrchr";
const char key07[] PROGMEM  = "memset";
const char key08[] PROGMEM  = "strcat";
const char key09[] PROGMEM  = "strchr";
const char key10[] PROGMEM  = "strcmp";
const char key11[] PROGMEM  = "strcpy";
const char key12[] PROGMEM  = "strlen";
const char key13[] PROGMEM  = "strlwr";
const char key14[] PROGMEM  = "strstr";
const char key15[] PROGMEM  = "strupr";

// PGM_P const key_list[ keys ] PROGMEM =
const char * const key_list[ keys ] PROGMEM =
{
  key00, key01, key02, key03, key04, key05, key06, key07, key08, key09,
  key10, key11, key12, key13, key14, key15
};

const byte branch[ keys ][ keylen ] PROGMEM =
{
  8, 255, 255, 4, 1, 255, 255, 255,
  8, 255, 255, 4, 2, 255, 255, 255,
  8, 255, 255, 4, 3, 255, 255, 255,
  8, 255, 255, 4, 255, 255, 255, 255,
  8, 255, 255, 6, 5, 255, 255, 255,
  8, 255, 255, 6, 255, 255, 255, 255,
  8, 255, 255, 7, 255, 255, 255, 255,
  8, 255, 255, 255, 255, 255, 255, 255,
  255, 255, 255, 12, 9, 255, 255, 255,
  255, 255, 255, 12, 10, 255, 255, 255,
  255, 255, 255, 12, 11, 255, 255, 255,
  255, 255, 255, 12, 255, 255, 255, 255,
  255, 255, 255, 14, 13, 255, 255, 255,
  255, 255, 255, 14, 255, 255, 255, 255,
  255, 255, 255, 15, 255, 255, 255, 255,
  255, 255, 255, 255, 255, 255, 255, 255
};

const byte startChar[ 52 ] PROGMEM = // first word starting with A-Z / a-z
{
  255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // A-M
  255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // N-Z
  255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,   0, // a-m
  255, 255, 255, 255, 255,   8, 255, 255, 255, 255, 255, 255, 255  // n-z
};


//PGM_P current_key;
const char * current_key;
char idx, data, notDone, done;

byte  printFlash( const char * FM )
{
  byte c;
  byte  fb; // flash byte
  c = 0;
  do
  {
    c++;
    fb = pgm_read_byte( FM++ );
    if ( fb )  Serial.print(( char ) fb );
  }
  while ( fb );
  return c;
}


void setup()
{
  Serial.begin( 115200 );
  Serial.println( F( "\n\nTEST\n" ));

  myList.keysInList = keys;
  myList.keyList = (const char *)pgm_read_word( key_list[ 0 ] );
  myList.branchList = (const char *)pgm_read_word( branch );
  myList.firstChars = startChar;
}

void loop()
{

  if ( Serial.available())
  {
    data = Serial.read();

    if (( data == '\n' ) || ( data == ' ' )) // end of line delimiter is ASCII newline
    {
      Serial.println();
    }
    else
    {

// comment these out and it compiles for Mega and Uno
// leave them in and Uno is no-go      
      myList.match( data );
      Serial.println( myList.state );
      
    }
  }
}
// Under Construction
// dictionary_w_branch.cpp ver 1.0 by GoForSmoke @ Arduino Forum
// Free for use, Apr 30th, 2016
//
// Put the example and library files in the project folder.

#include "Arduino.h"
#include <avr/pgmspace.h>
#include "dictionary_w_branch.h"

// match states 0 = waiting, 1 = matching, 2 = matched, 4 = no match

unsigned char findMatch::match( char text ) // returns match state
{
  static char charToMatch;
  static byte wordIndex, idx;

  if (( state == 2 ) || ( state == 4 )) return state; // 4 = no match, ignore text

  if ( text < 'A' ) // anything less than A is now a delimiter
  {
    charsMatched = state = 0;
  }
  else if ( !(( text >= 'A' && text <= 'Z' ) || ( text >= 'a' && text <= 'z' ))) // illegal
  {
    charsMatched = 0;
    state = 4;
  }
  else
  {
    Serial.println( );
    Serial.print( text );
    Serial.print( " - " );

    switch ( state )
    {
      case 0 : // 0 = waiting
        if ( text < 'a' ) idx = text - 'A';
        else              idx = text - 'a';

        wordIndex = pgm_read_byte( firstChars + idx );
        if ( wordIndex == 255 )
        {
          charsMatched = 0;
          state = 4;
        }
        else
        {
          currentKey = (const char *)pgm_read_word( keyList + wordIndex );
          charsMatched = 1;
          state = 1;
        }
        break;

      default :  //  2 = matched, 4 = no match, let it read till delimiter.
        break;
    }
  }

  return state;
}
// Under Construction
// dictionary_w_branch.h ver 1.0 by GoForSmoke @ Arduino Forum
// Free for use, Apr 30th, 2016
//
// Put the example and library files in the project folder.

#ifndef dictionary_w_branch_h
#define dictionary_w_branch_h

#include "Arduino.h"
#include <avr/pgmspace.h>

class findMatch
{
public:
  byte match( char );
  byte state; // 0 = waiting, 1 = matching, 2 = matched, 4 = no match  
  byte charsMatched;

  byte keysInList;
  const char * keyList;
  const char * branchList;
  const char * currentKey; 
  const byte * keyBranch;
  const byte * firstChars;
};

#endif