structured assembler (BASIC) [Really: C builtin functions?]

Gregory Smith greg at utcsri.UUCP
Mon Apr 28 06:24:38 AEST 1986


In article <375 at hadron.UUCP> jsdy at hadron.UUCP (Joseph S. D. Yao) writes:
>In article <6584 at utzoo.UUCP> henry at utzoo.UUCP (Henry Spencer) writes:
>>[unattributed]
>>> ... but sizeof qualifies as a builtin function, 
>>> even though it is a compile-time function vs run-time.   Anyone disagree?
>>Fraid so.  Sizeof is an *operator*, which can (but does not have to be)
>>invoked with a function-like syntax.  ...
>
>Any operator which maps its args into a unique value in its range
>defines an operation which is a function.  Just because you can
>say a + b doesn't mean that (plus a b) [resp., plus(a, b)] is not
>a function.  Similarly, sizeof(i), whether or not you use parens
>(and I always do) is an operator which, of course, is a function.

sizeof is NOT a C function ( 'function' is used in the C language sense
and not in the mathematical sense ). Operators and functions are distinct
in terms of the language definition.

Consider the following ( the first two have been posted many times; I have
not seen the third one yet ).

(1)	`sizeof( int * )' is obviously not a function call, but is valid.

(2)	`sizeof foo' is not a function call, but is valid.

(3)	`sizeof(foo)' looks like a function call, but is _used_to_obtain_
	_symbol_table_information_that_is_not_necessarily_available_at_run_
	_time_. It would not be possible to write a run-time function in C
	or assembler that would act in the same way that sizeof does. E.g.
	an 'int' would be passed whether 'foo' was 'int' or 'char', so even
	if you had the ability to measure the size of the parameter block,
	which is not often the case, it couldn't be done.

So enough already ! ! ! ! ! ! ! !

Incidentally, in this sense, a+b is very different from a function.
`a+b' does many different things depending on the types of a and b.
(a=float, b=int; a=char,b=long etc) A C-callable function of the form
plus(a,b) would obviously not do this.

Another point: C functions don't even map their args into a unique value.
consider getc(f) in the case where f is always the run-time constant 'stdin'.


-- 
"For every action there is an equal and opposite malfunction"
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg



More information about the Comp.lang.c mailing list