Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang,net.lang.c Subject: Re: structured assembler (BASIC) [Really: C builtin functions?] Message-ID: <2662@utcsri.UUCP> Date: Sun, 27-Apr-86 16:24:38 EDT Article-I.D.: utcsri.2662 Posted: Sun Apr 27 16:24:38 1986 Date-Received: Sun, 27-Apr-86 16:56:24 EDT References: <443@3comvax.UUCP> <6584@utzoo.UUCP> <375@hadron.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 48 Keywords: BASIC, C, operator, function Summary: sizeof is not, was not, never will be a function, so stop it!!!!! In article <375@hadron.UUCP> jsdy@hadron.UUCP (Joseph S. D. Yao) writes: >In article <6584@utzoo.UUCP> henry@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