Subject: Re: Allegro CL foreign function interface
From: Erik Naggum <>
Date: 2000/06/15
Newsgroups: comp.lang.lisp
Message-ID: <>

* "Sandeep Koranne" <>
| Maybe I have not understood your comment correctly, but it seems to
| me that C/C++ main fiunction does NOT get a zero terminated vector
| (a vector by definitin is a single dimension array) while in C/C++
| the arguments to main are, int main (int argc, char* argv[]) : or a
| vector or vectors.  So we DO need both the count of argument and the
| Vector of Vectors (the elements of argv are of course ZERO
| terminated strings).

  C's conventional variable-sized vector representation is that

(aref <vector> (length <vector>)) => nil

  to put it in more familiar terms, and this holds for all vectors of
  all types, with varying representations of nil, of course, but they
  are generally just warped versions of the integer 0, which is, of
  course, just a convenient bit pattern of all zeros.  A string has a
  character conflatable with the integer 0, the NUL, and a vector of
  any pointer type has a void * conflatable with the integer 0, the
  NULL.  So it may be more proper to say "NULL-terminated" than "zero-
  terminated", although the semantics of NULL is strictly that of a
  machine representation of zero.  Let's not give C any more credit
  than it deservers, is my line.

  The count is in fact unnecessary, as witnessed by the fact that the
  exec* family of system calls actually transmit only the variable-
  sized vector of arguments and optionally environment bindings to the
  kernel, which transmits them as such to the C runtime library, which
  _then_ traverses the argument list and counts the arguments and
  passes them to the main function with a count, for convenience.

  I happen to think that this count-as-well-as-null-termination thing
  is one of C's fundamentally braindamaged design decisions, having
  caused an enormous amount of problems for programmers who don't get
  the idea that it's a sometime convenience, not a pattern to learn by
  rote and repeat uncritically, no matter how counter-productive.
  If this is not what you expected, please alter your expectations.