title: Casting between structs?
body: <p>I'm working on a code base in which we have several configurable types. One of those types is 64 bit integer. When we compile for platforms that have no native 64 bit integer type, we simple represent 64 bit integers using a struct similar to</p>
  
  <pre><code>typedef struct {
      unsigned int hi, lo;
  } int64;
  </code></pre>
  
  <p>In order to make this type useful, all common operations are defined as functions such as</p>
  
  <pre><code>int64 int64_add(int64 x, int64 y);
  </code></pre>
  
  <p>On platforms where a native 64 bit integer type is available, these operations simply look like</p>
  
  <pre><code>#define int64_add(x, y) ((x) + (y))
  </code></pre>
  
  <p>Anyway, on to the question. I am implementing some functionality regarding time and I want to represent my time using the 64 bit integer:</p>
  
  <pre><code>typedef int64 mytime;
  </code></pre>
  
  <p>I also want all the common operations available to the int64 type to be available for my time type as well:</p>
  
  <pre><code>#define mytime_add(x, y) (mytime) int64_add((int64) (x), (int64) (y))
  </code></pre>
  
  <p>The problem with this is that the casts between the types mytime and int64 isn't allowed in C (as far as I can tell anyhow). Is there any way to do this without having to reimplement all the add, sub, mul, div, etc functions for the mytime type?</p>
  
  <p>One option is of course to never do the mytime typedef and simply use int64 everywhere I need to represent time. The problem with this is that I'm not sure if I always want to represent time as a 64 bit integer. Then there's the issue of readable code as well... :-)</p>