title: gcc: printf and long double leads to wrong output. [C - Type conversion messes up]
body: <p>I'm fairly new to C. I try to write functions for a Vector, but there must be something wrong.<br>
  Here's the code:</p>
  
  <pre><code>/* Defines maths for particles. */
  
  #include &lt;math.h&gt;
  #include &lt;stdio.h&gt;
  
  /* The vector struct. */
  typedef struct {
      long double x, y, z;
  } Vector;
  
  Vector Vector_InitDoubleXYZ(double x, double y, double z) {
      Vector v;
      v.x = (long double) x;
      v.y = (long double) y;
      v.z = (long double) z;
      return v;
  }
  
  Vector Vector_InitDoubleAll(double all) {
      Vector v;
      v.x = v.y = v.z = (long double) all;
      return v;
  }
  
  
  Vector Vector_InitLongDXYZ(long double x, long double y, long double z) {
      Vector v;
      v.x = x;
      v.y = y;
      v.z = z;
      return v;
  }
  
  Vector Vector_InitLongDAll(long double all) {
      Vector v;
      v.x = v.y = v.z = all;
      return v;
  }
  
  Vector Vector_AddVector(Vector *v1, Vector *v2) {
      Vector v3;
      v3.x = v1-&gt;x + v2-&gt;x;
      v3.y = v1-&gt;y + v2-&gt;y;
      v3.z = v1-&gt;z + v2-&gt;z;
      return v3;
  }
  
  Vector Vector_AddDouble(Vector *v1, double other) {
      Vector v2;
      v2.x = v1-&gt;x + other;
      v2.y = v1-&gt;y + other;
      v2.z = v1-&gt;z + other;
      return v2;
  }
  
  Vector Vector_AddLongD(Vector *v1, long double other) {
      Vector v2;
      v2.x = v1-&gt;x + other;
      v2.y = v1-&gt;y + other;
      v2.z = v1-&gt;z + other;
      return v2;
  }
  
  void Vector_Print(Vector *v) {
      printf("X: %Lf, Y: %Lf, Z: %Lf\n", v-&gt;x, v-&gt;y, v-&gt;z); //Before edit: used %ld
  }
  
  double Vector_Length(Vector *v) {
      return pow(pow(v-&gt;x, 2) + pow(v-&gt;y, 2) + pow(v-&gt;z, 2), 0.5);
  }
  
  
  
  int main() {
      Vector v = Vector_InitDoubleXYZ(2.0, 1.0, 7.0); //Before edit: (2.0d, 1.0d, 7.0d);
  
      Vector_Print(&amp;v);
  }
  </code></pre>
  
  <p>I'm using gcc to compile. Running  <code>vector.exe</code> in the commandline gives me the following output:</p>
  
  <blockquote>
    <p>X: 0, Y: -2147483648, Z: 9650176</p>
  </blockquote>
  
  <p>and I do not understand why this is happening.</p>
  
  <p>I appreciate any hints (even about my coding-style or whatever could've be done better in the code).<br>
  Thank you,</p>
  
  <h2><strong>Update</strong>: Using the MSVC Compiler works just fine, it seems to be an issue of gcc. Do you know why this happens ?</h2>