title: Pointer to constant string in struct
body: <p>I'm writing in C.</p>
  
  <p>In <code>header1.h</code> I declare a pointer to a constant string (a constant array of <code>char</code>), a new type with a struct and a variable of this type, and another variable:</p>
  
  <pre><code>const char *str_ptr = "Hello world!";
  
  struct entry_t {
  const char *text;
  int var;
  };
  typedef entry_t entry;
  
  extern entry start_entry;
  
  int a;
  </code></pre>
  
  <p>In the file <code>func.c</code> I define the new variable:</p>
  
  <pre><code>#include "header1.h"
  
  entry start_entry = {str_ptr, a};
  
  void func(void)
  {
      //here i use start_entry
  }
  </code></pre>
  
  <p>But the compiler report me the error </p>
  
  <blockquote>
    <p>constant expression required</p>
  </blockquote>
  
  <p>referring to the initialization of <code>start_entry</code>, and in particular of the <code>const char*</code> member.
  Why? Where is the error?</p>
  
  <p>Naturally if I define the string as</p>
  
  <pre><code>const char str[] = "Hello world!";
  </code></pre>
  
  <p>and then the <code>entry</code> variable as</p>
  
  <pre><code>entry start_entry = {&amp;str, a};
  </code></pre>
  
  <p>everything is ok.</p>
  
  <p><strong>EDIT_1</strong></p>
  
  <p>I've made two errors in reporting my code:</p>
  
  <ol>
  <li><p>var is <code>const</code> too</p>
  
  <p>struct entry_t {
  const char *text;
  const int var;
  };</p></li>
  <li><p>in func.c <em>entry</em> is <code>const</code> too</p>
  
  <p>const entry start_entry;</p></li>
  </ol>
  
  <p><strong>EDIT_2</strong></p>
  
  <p>I don't care of <em>var</em>, my interest is on <code>const char *</code> member (even if maybe the problem is the same: i write wrong code before, also with <code>int var</code> i had an error...).
  I'm going to redefine all:</p>
  
  <pre><code>//header1.h
  
  const char *str_ptr = "Hello world!";
  
  struct entry_t {
  const char *text;
  };
  typedef entry_t entry;
  
  extern const entry start_entry;
  
  
  //func.c
  #include header1.h
  
  const entry start_entry = {str_ptr};
  
  void func(void)
  {
      //here i use start_entry
  }
  </code></pre>
  
  <p>I can't understand why <em>start_entry</em> has a <code>const char*</code> member, i define it with a <code>const char*</code> but there is that error.</p>