On Wed, 27 Oct 2010 22:55:33 +0100, Ben Bacarisse
Is an implementation conforming if you can't pass a size_t to a function
without a prototype? I think calling
extern void *my_alloc();
long *lp = my_malloc(sizeof *lp);
does what I was trying to do -- the argument is promoted and then
assigned so it is an int that is assigned to the (non-prototype)
size_t parameter (not shown).
If I have correctly untangled your negatives, yes it is (must be)
allowed to pass size_t -- to a 'user' function (one written in C).
6.5.2.2p6 formerly 6.3.2.2 defines the cases where a call, using
either prototype or K&R1 declaration, works with a definition, ditto.
You absolutely can define K&R1 taking size_t and call K&R1 passing
size_t and it works, and I'm pretty sure that's what you mean your
example to be. IF size_t is narrower than int or u-int, yes K&R1 call
promotes it and K&R1 definition demotes it back. But I don't think
I've ever seen a platform where it makes sense for size_t to be
narrower than u/int. The case that has occurred frequently in the
past, and again now with 64-bit machines, is size_t wider than int.
Then K&R1 call passes it as-is and K&R1 definition takes it as-is.
You can define with SOME prototype and call K&R1 with size_t -- but
that prototype type is implementation dependent. If you define K&R1
with size_t, it's implementation dependent whether you can make any
prototype call that matches and if so what.
But it isn't clear the same rules apply to standard library functions,
which needn't be implemented in C -- and some at least usually aren't.
On most(?) implementations library functions do use the same calling
sequence(s) as user functions, but it isn't explicitly required.
Although a call through a (compatible) pointer must handle either.
(Plus an apparent library call may actually be a macro invocation,
but you can #undef or (parenthesize) to get an actual call.)