user23366: I'm implementing a voice synthesizer chip. To build a phrase, I create a list of phonemes like this:
static const uint8_t PROGMEM heybuddy[] = {
  pPA5, pHH1, pEY, pPA5,
  pBB2, pAX, pDD2, pIY, pPA5,pPA5,pPA5,
};

And to play them I do this:
 for (size_t i=0; i<sizeof(heybuddy); i++){
    say(pgm_read_byte(heybuddy+i));
 }

So what I'd like to do is create a function where I can just pass the array to a function that can take care of the loop and do some other maintenance stuff. 
//what I've tried: 
void sayPhrase(const uint8_t *phrase){
  int open = 0;
  for (size_t i=0; i<sizeof(*phrase); i++){

      if(pgm_read_byte(*phrase) != 4 && open == 0){
          Serial.println("mouth open");
          open = 1;
      } else if(pgm_read_byte(*phrase) == 4 && open == 1){
         Serial.println("mouth closed");
         open = 0;
      }
      say(pgm_read_byte(*phrase+i));
    } 
}

But when it comes to passing a static const I'm lost I've tried passing it as a reference with * but nothing I do seems to work - I just don't know the proper way to do this in C.
What I have compiles, but it seems to only get one phoneme and repeat it over and over. The rest are lost.

user11763: The problem is, when you call sizeof(*phrase), what is returned is 1, the size of the uint8_t array element, the result of your pointer de-reference. On the other hand, if you call sizeof(phrase) inside the function, you get the size of the pointer itself and not the size of the array, as you might expect. When you pass the array to the function via a pointer, the function has no idea if you passed the start of an array to it or merely a pointer to some uint8_t variable, so it can't know what the size is; context has been lost.
Instead, you should call sizeof(phrase) in the same scope where the array was declared and initialized and pass the result to the function, which can then use this value in the for loop.
static const uint8_t PROGMEM heybuddy[] = {
  pPA5, pHH1, pEY, pPA5,
  pBB2, pAX, pDD2, pIY, pPA5,pPA5,pPA5,
};

size_t SIZE = sizeof(heybuddy);  // this is ok since each element = 1 byte

sayPhrase(phrase, SIZE);

The function definition should be:
void sayPhrase(const uint8_t *phrase, size_t size){
  int open = 0;
  for (size_t i=0; i < size; i++){

      if(pgm_read_byte(phrase) != 4 && open == 0){
          Serial.println("mouth open");
          open = 1;
      } else if(pgm_read_byte(phrase) == 4 && open == 1){
         Serial.println("mouth closed");
         open = 0;
      }
      say(pgm_read_byte(phrase+i));
    } 
}


user10794: I have some extensive examples of accessing PROGMEM here.
I've adapted one of the examples to show how you might do something similar to what you want:
const int NUMBER_OF_ELEMENTS = 10;

const char Message0000 [] PROGMEM = "Twas bryllyg, and ye slythy toves"; 
const char Message0001 [] PROGMEM = "Did gyre and gymble"; 
const char Message0002 [] PROGMEM = "in ye wabe:"; 
const char Message0003 [] PROGMEM = "All mimsy were ye borogoves; And ye mome raths outgrabe."; 
const char Message0004 [] PROGMEM = "\"Beware the Jabberwock, my son! \n The jaws that bite, the claws that catch!"; 
const char Message0005 [] PROGMEM = "Beware the Jubjub bird, and shun\n The frumious Bandersnatch!\""; 
const char Message0006 [] PROGMEM = "He took his "; 
const char Message0007 [] PROGMEM = "vorpal sword in hand:"; 
const char Message0008 [] PROGMEM = "Long time the manxome foe he sought - "; 
const char Message0009 [] PROGMEM = "So rested he by the Tumtum tree, \n And stood awhile in thought."; 

const char * const messages[NUMBER_OF_ELEMENTS] PROGMEM = 
   { 
   Message0000, 
   Message0001, 
   Message0002, 
   Message0003, 
   Message0004, 
   Message0005, 
   Message0006, 
   Message0007, 
   Message0008, 
   Message0009, 
   };

void sayPhrase (const char * const * message)
  {
  const char * ptr = reinterpret_cast<const char *>(pgm_read_ptr (message));  // pointer to message
  Serial.println(reinterpret_cast<const __FlashStringHelper *>(ptr));    // and print it
  } // end of sayPhrase

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  for (int i = 0; i < NUMBER_OF_ELEMENTS; i++)
    sayPhrase (&messages [i]);

  }  // end of setup

void loop () { } 


user8384: If you're not averse to a bit of C++:
void sayPhrase(const uint8_t * phrase, size_t size)
{
    bool open = false;
    for (size_t i = 0; i < size; ++i)
    {
        if(pgm_read_byte(phrase) != 4 && !open)
        {
            Serial.println("mouth open");
            open = true;
        }
        else if(pgm_read_byte(phrase) == 4 && open)
        {
            Serial.println("mouth closed");
            open = false;
        }
        say(pgm_read_byte(&phrase[i]));
    } 
}

template< size_t size >
void sayPhrase(const uint8_t (&phrase)[size])
{
    sayPhrase(phrase, size);
}

Which can then be called directly on the array:
sayPhrase(heybuddy);

And the template will infer the array size and call the non-template function.

23366: <p>I'm implementing a voice synthesizer chip. To build a phrase, I create a list of phonemes like this:</p>

<pre><code>static const uint8_t PROGMEM heybuddy[] = {
  pPA5, pHH1, pEY, pPA5,
  pBB2, pAX, pDD2, pIY, pPA5,pPA5,pPA5,
};
</code></pre>

<p>And to play them I do this:</p>

<pre><code> for (size_t i=0; i&lt;sizeof(heybuddy); i++){
    say(pgm_read_byte(heybuddy+i));
 }
</code></pre>

<p>So what I'd like to do is create a function where I can just pass the array to a function that can take care of the loop and do some other maintenance stuff. </p>

<pre><code>//what I've tried: 
void sayPhrase(const uint8_t *phrase){
  int open = 0;
  for (size_t i=0; i&lt;sizeof(*phrase); i++){

      if(pgm_read_byte(*phrase) != 4 &amp;&amp; open == 0){
          Serial.println("mouth open");
          open = 1;
      } else if(pgm_read_byte(*phrase) == 4 &amp;&amp; open == 1){
         Serial.println("mouth closed");
         open = 0;
      }
      say(pgm_read_byte(*phrase+i));
    } 
}
</code></pre>

<p>But when it comes to passing a static const I'm lost I've tried passing it as a reference with <code>*</code> but nothing I do seems to work - I just don't know the proper way to do this in C.</p>

<p>What I have compiles, but it seems to only get one phoneme and repeat it over and over. The rest are lost.</p>
 11763: <p>The problem is, when you call <code>sizeof(*phrase)</code>, what is returned is 1, the size of the <code>uint8_t</code> array element, the result of your pointer de-reference. On the other hand, if you call <code>sizeof(phrase)</code> inside the function, you get the size of the pointer itself and not the size of the array, as you might expect. When you pass the array to the function via a pointer, the function has no idea if you passed the start of an array to it or merely a pointer to some <code>uint8_t</code> variable, so it can't know what the size is; context has been lost.</p>

<p>Instead, you should call <code>sizeof(phrase)</code> in the same scope where the array was declared and initialized and pass the result to the function, which can then use this value in the <code>for</code> loop.</p>

<pre><code>static const uint8_t PROGMEM heybuddy[] = {
  pPA5, pHH1, pEY, pPA5,
  pBB2, pAX, pDD2, pIY, pPA5,pPA5,pPA5,
};

size_t SIZE = sizeof(heybuddy);  // this is ok since each element = 1 byte

sayPhrase(phrase, SIZE);
</code></pre>

<p>The function definition should be:</p>

<pre><code>void sayPhrase(const uint8_t *phrase, size_t size){
  int open = 0;
  for (size_t i=0; i &lt; size; i++){

      if(pgm_read_byte(phrase) != 4 &amp;&amp; open == 0){
          Serial.println("mouth open");
          open = 1;
      } else if(pgm_read_byte(phrase) == 4 &amp;&amp; open == 1){
         Serial.println("mouth closed");
         open = 0;
      }
      say(pgm_read_byte(phrase+i));
    } 
}
</code></pre>
 10794: <p>I have some extensive examples of accessing PROGMEM <a href="http://www.gammon.com.au/progmem" rel="nofollow noreferrer">here</a>.</p>

<p>I've adapted one of the examples to show how you might do something similar to what you want:</p>

<pre class="lang-c++ prettyprint-override"><code>const int NUMBER_OF_ELEMENTS = 10;

const char Message0000 [] PROGMEM = "Twas bryllyg, and ye slythy toves"; 
const char Message0001 [] PROGMEM = "Did gyre and gymble"; 
const char Message0002 [] PROGMEM = "in ye wabe:"; 
const char Message0003 [] PROGMEM = "All mimsy were ye borogoves; And ye mome raths outgrabe."; 
const char Message0004 [] PROGMEM = "\"Beware the Jabberwock, my son! \n The jaws that bite, the claws that catch!"; 
const char Message0005 [] PROGMEM = "Beware the Jubjub bird, and shun\n The frumious Bandersnatch!\""; 
const char Message0006 [] PROGMEM = "He took his "; 
const char Message0007 [] PROGMEM = "vorpal sword in hand:"; 
const char Message0008 [] PROGMEM = "Long time the manxome foe he sought - "; 
const char Message0009 [] PROGMEM = "So rested he by the Tumtum tree, \n And stood awhile in thought."; 

const char * const messages[NUMBER_OF_ELEMENTS] PROGMEM = 
   { 
   Message0000, 
   Message0001, 
   Message0002, 
   Message0003, 
   Message0004, 
   Message0005, 
   Message0006, 
   Message0007, 
   Message0008, 
   Message0009, 
   };

void sayPhrase (const char * const * message)
  {
  const char * ptr = reinterpret_cast&lt;const char *&gt;(pgm_read_ptr (message));  // pointer to message
  Serial.println(reinterpret_cast&lt;const __FlashStringHelper *&gt;(ptr));    // and print it
  } // end of sayPhrase

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  for (int i = 0; i &lt; NUMBER_OF_ELEMENTS; i++)
    sayPhrase (&amp;messages [i]);

  }  // end of setup

void loop () { } 
</code></pre>
 8384: <p>If you're not averse to a bit of C++:</p>

<pre><code>void sayPhrase(const uint8_t * phrase, size_t size)
{
    bool open = false;
    for (size_t i = 0; i &lt; size; ++i)
    {
        if(pgm_read_byte(phrase) != 4 &amp;&amp; !open)
        {
            Serial.println("mouth open");
            open = true;
        }
        else if(pgm_read_byte(phrase) == 4 &amp;&amp; open)
        {
            Serial.println("mouth closed");
            open = false;
        }
        say(pgm_read_byte(&amp;phrase[i]));
    } 
}

template&lt; size_t size &gt;
void sayPhrase(const uint8_t (&amp;phrase)[size])
{
    sayPhrase(phrase, size);
}
</code></pre>

<p>Which can then be called directly on the array:</p>

<pre><code>sayPhrase(heybuddy);
</code></pre>

<p>And the template will infer the array size and call the non-template function.</p>
