[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: K&R C Questions



pitz wrote:
On Sep 2, 9:51 am, Harry Potter <maspethro...@aol.com> wrote:
I want to produce and use C compilers for Commodore computers.  I
tried asking these questions in the appropriate newsgroup
(comp.sys.cbm) but received no adequate response: How do I define a
function with no parameters?  What libraries and library functions are
available?  How do I handle the passing of non-int parameters?  Are
they converted to ints, or are they passed in the size of the
operation?  BTW, I may create it for the Apple 2--if I actually finish
the Commodore versions. :)
---------------
Joseph Rose, a.k.a. Harry Potter
Working magic in the computer community...or at least striving to! :(

Functions with no parameters are defined like:
  // return type is assumed as int
  f()
  {
    ...
  }
  // explicit return type
  float f()
  {
    ...
  }
Functions with non-int params:
  f(x, y, z)
  float x, int y, double z;
  {
    ...
  }

Most C implementations pass value parameters through the stack, each
value can have different number of bytes used.

Any integer type (char or short) is *promoted* to a regular int *before* pushing on the stack for a function call. A float is promoted to a double before pushing on the stack as a parameter. Arrays are passed as a pointer to the first element of the array.

Why not produce an ANSI C compiler instead of K&R?

ANSI C is more complex than K&R C. So producing the K&R compiler should be easier.


--
+----------------------------------------+
|     Charles and Francis Richmond       |
|                                        |
|  plano dot net at aquaporin4 dot com   |
+----------------------------------------+