title: How to hold a const value in a struct in C (not C++)?
body: <p>How can I hold a constant value in a struct? If I put const at LEBEL0 I would not be able to assign to it at LEBEL1. But if I do not put const at LEBEL0, then I will get qualifier lost warning at LEBEL1. Is there any way to do this? I came up with a dirty solution (below) but I think there could be a better one...</p>
  
  <pre><code>    typedef struct _MyStruct
      {
          const SomePointerType pktData; &lt;--LABEL0
      }MyStruct;
  
      const SomePointerType SomeFunctionICannotModify()
      {
      …
      }
  
      void SomeFunction()
      {
         MyStruct data;
      ….
         data.pktData = SomeFunctionICannotModify(); &lt;--LABEL1
     ....
         SomeSubFunction(&amp;data);
      }
  
      void SomeSubFunction(MyStruct* data)
      {
          this function does not modify any fields in "data".
      }
  </code></pre>
  
  <p>PS: The code above is a "model", not a real code, to illustrate my problem. It does not have all the codes in my actual program. Please do not ask questions like "why would you do that", "you do not have to do that", "that code does not compile" and so on.</p>
  
  <p>My dirty solution</p>
  
  <pre><code>    typedef struct _ConstHolder
      {
          const SomePointerType pktData;
      }ConstHolder;
  
      typedef struct _MyStruct
      {
          ConstHolder holder;
      }MyStruct;
  
      void SomeFunction()
      {
         MyStruct data;
      ….
         ConstHolder holder = {SomeFunctionICannotModify()};
         data.holder = holder;
     ....
         SomeSubFunction(&amp;data);
      }
  </code></pre>