On the issue of float, double and long

#include <stdio.h>
// Test environment:
//    Thinkpad Lenovo x201 -- 64bit, gcc 4.5.1, Linux Fedora

int main()
{
  // [0] error: both ‘long’ and ‘float’ in declaration specifiers
  // [1] error: both ‘long long’ and ‘double’ in declaration specifiers

  int a = 1;
  long int b = 1;
  int long c = 1;
  long long int d = 1;
  int long long e = 1;

  float f = 1.0;
  //float long g = 1.0; // [0]
  //long float h = 1.0; // [0]
  //float long long i = 1.0; // [0] [0]
  //long long float j = 1.0; // [0]

  double o = 1.0;
  long double p = 1.0;
  double long q = 1.0;
  //long long double r = 1.0; // [1]
  //double long long s = 1.0; // [1]

  printf("%zun", sizeof(a)); // 4
  printf("%zun", sizeof(b)); // 8
  printf("%zun", sizeof(c)); // 8
  printf("%zun", sizeof(d)); // 8
  printf("%zun", sizeof(e)); // 8
  printf("%zun", sizeof(f)); // 4
  printf("%zun", sizeof(o)); // 8
  printf("%zun", sizeof(p)); // 16
  printf("%zun", sizeof(q)); // 16
  printf("%lfn", o); // 1.000000
  return 0;
}
  1. Why is “double” not “long float”? Replace “double” with “float long” in the example above and you will recognize some consistency.
  2. See the line before “return 0″. Double is semantically a “long float” for printf.
  3. Why is the error of “float long long” printed twice?
  4. As everybody should know, datatypes of C are not bound to any length of size. [wiki]
  5. According to GCC, “float” is defined as “float” < “double” < “double long” with a radix of 2
  6. I don’t like C :-(

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>