standardizing on binary units

Robert P. J. Day rpjday at mindspring.com
Tue May 2 12:42:43 UTC 2006


  another aesthetic nitpick but, if include/libbb.h is going to define
the enumeration constants:

enum {
    KILOBYTE = 1024,
    MEGABYTE = (KILOBYTE*1024),
    GIGABYTE = (MEGABYTE*1024)
};

it only makes sense that busybox code should start using those
constants, rather than constantly reproduce numeric constants like
"1024", "65536" and so on.  however, while this might seem nitpicky,
it's not that simple.

  first, the above enum constant definitions are simply wrong.  1024
is not equivalent to a "kilobyte", it's equivalent only to a "kilo" if
you want to be pedantic about it.  there's nothing that requires that
value to refer specifically to a number of *bytes*.  but that's not
the biggest problem.

  the new IEC standard prefixes:

http://physics.nist.gov/cuu/Units/binary.html

now more carefully define binary multiples to distinguish them from
simple powers of ten.  if you want to be precise, you might want to
define macros or enum constants like:

  Ki = 1024
  Mi = 1048576

and so on, so you can more precisely use values like "64 * Ki" or "4 *
Mi" or whatever.

  in any event, it *is* rather pointless to define those enum
constants, then make so little use of them.

rday



More information about the busybox mailing list