HN user

mnaydin

9 karma
Posts0
Comments14
View on HN
No posts found.

I am not able to understand how

  int (*ap3)[900000] = malloc(sizeof *ap3);
is nicer than
  int *a = malloc(900000 * sizeof *a);
Notice that, in the former case, the array elements must be accessed as (*ap3)[i] whereas in the latter case the usual method a[i] is fine.

I am reminded of Fortran 77. In Fortran 77, the first character of a record to be printed out determined vertical spacing as follows:

    Blank     One line
      0       Two lines
      1       To first line of next page
      +       No advance

A modern compiler would warn about the condition (ii >= 0) being always true.

One correct way would be

  for (size_t i = len; i > 0; --i) {
     // use i-1 as the array index
  }
or,
  size_t i = len
  while (i-- > 0) {
    // use i as the array index
  }

"C99 provides a macro SIZE_MAX with the maximum value possible in size_t. C89 doesn’t have it, although you can obtain the value by casting (size_t)-1. This assumes a twos’ complement architecture,..."

The architecture does not have to be two's-complement. The value of the expression (size_t)(-1) will always be SIZE_MAX, the largest number that can be represented in the size_t type. The bit pattern may change depending on the architecture, but the value shall equal to SIZE_MAX.

Neither -b nor -B option is defined in the POSIX ls utility. The -b option is a GNU extension to print C-style escapes for nongraphic characters, and it is useful for this case. The -B option is also GNU extension not to list implied entries ending with ~, and I don't understand how it is relevant to this case.

I'd use the find command with the -printf option (GNU find has this option but POSIX find doesn't define it) instead of ls. For instance:

find /path/to/dir -type f -printf "%s\n" | awk ' { s += $0 } END { print s " bytes" } '

The find command has much powerful file filtering capabilities than that of the ls command and works better with weird characters in filenames.