title: How to call a C function in Fortran and properly pass uint32_t arguments
body: <p>Hi I am using a Fortran 90 code to call a C function. Since I am manipulating addresses, the arguments of the C function should be properly matched in Fortran. I am using ifort and icc to compile the code and working on 64 bit machine.</p>
  
  <p>Some testing showed that this will work also with <code>int32_t</code>, although to prevent eventual pitfalls, I would like to keep the <code>uint32_t</code>  </p>
  
  <p>The C functions I am calling has the following prototypes </p>
  
  <pre><code>uint32_t encode_(uint32_t x, uint32_t y)
  uint32_t decode_(uint32_t dec)
  </code></pre>
  
  <p>I can't call these functions simply by doing something like</p>
  
  <pre><code>integer :: cod,encode
  cod = encode(i,j)
  </code></pre>
  
  <p>This will produce gibberish. Therefore I am using a workaround:</p>
  
  <pre><code>void code2d_(uint32_t j[] ){
  
  
  uint32_t i;
  
  i=encode_(j[0],j[1]);  
  // the underscore is due to the FORTRAN naming convention
  
  printf("Coded %10d  \n",i);
  
  }
  </code></pre>
  
  <p>And subsequently in Fortran</p>
  
  <pre><code> integer :: cod,code2d
   cod = code2d(i,j)
  </code></pre>
  
  <p>Well obviously I have some problem with the mismatch of the argument types. Unfortunately I don't know how to fix this. Since in my decode/encode functions binary address arithmetic is done it is quite important to preserve the <code>uint32_t</code>. </p>