[net.lang] ... C builtin functions?

avg@diablo.ARPA (Allen VanGelder) (04/10/86)

I think there may be a confusion in terminology between built-in and
in-line.  In FORTRAN, MAX is expanded in-line, so you always get
FORTRAN's MAX.  But SIN is not, and if you jiggle your libraries
properly you will get your personal SIN function.  The same is true
for READ and WRITE in FORTRAN.

I still call SIN, READ, and WRITE built-in in any language where the
language manual tells how to use them and what they do.

rwl@uvacs.UUCP (Ray Lubinsky) (04/13/86)

> >C has standard built-in functions????
  
> Well, how about sizeof(foo)?
> 
> It looks like a function invocation, and is known and understood
> by the compiler...

The thing is, sizeof() evaluates to a constant at run time, just like
'c'<<3  or  BUFSIZ  .  That makes it a pretty trivial function.  All it
really does is give you a portable, automatic facility for referring to
system dependencies.
-- 

Ray Lubinsky	University of Virginia, Dept. of Computer Science
		UUCP: ...!cbosgd!uvacs!rwl or ...!decvax!mcnc!ncsu!uvacs!rwl

jerry@ucbopal.berkeley.edu (Jerry Berkman) (04/16/86)

>In article <149@diablo.ARPA> avg@diablo.UUCP (Allen VanGelder) writes:
>>I think there may be a confusion in terminology between built-in and
>>in-line.  In FORTRAN, MAX is expanded in-line, so you always get
>>FORTRAN's MAX.  But SIN is not, and if you jiggle your libraries
>>properly you will get your personal SIN function.  The same is true
>>for READ and WRITE in FORTRAN.
>>
>>I still call SIN, READ, and WRITE built-in in any language where the
>>language manual tells how to use them and what they do.

Not true.  Try this program on with a 1977 standard compiler:

	print *, sin(1.0)
	end
	function sin(x)
	sin = 2.0
	end

When I compile it and run it on 4.3 BSD UNIX, I get:
  0.841471
sin() is an intrinsic listed in the standard, and you get it
even if there is a Fortran function you wrote with a similar name.
If you want your own function instead, you must say:

	external sin

and then sin() is no longer treated as an intrinsic in that program
unit.  If you write in assembler or C, you can create names to
fake out the Fortran standard, but not if you stay within Fortran.
By contrast, if you see sin(), or strcmp() or printf() in a C program,
there is no way of telling if that is refering to the commonly
referenced library routine or the program's author's own personal function.

	- Jerry Berkman
	  Academic Computing Services
	  U. C. Berkeley (415) 642-4804
	  jerry@ucbopal.Berkeley.EDU

ps@celerity.UUCP (Pat Shanahan) (04/16/86)

In article <149@diablo.ARPA> avg@diablo.UUCP (Allen VanGelder) writes:
>I think there may be a confusion in terminology between built-in and
>in-line.  In FORTRAN, MAX is expanded in-line, so you always get
>FORTRAN's MAX.  But SIN is not, and if you jiggle your libraries
>properly you will get your personal SIN function.  The same is true
>for READ and WRITE in FORTRAN.
>
>I still call SIN, READ, and WRITE built-in in any language where the
>language manual tells how to use them and what they do.


It is particularly important to keep this distinction between built-in and
in-line clear, because the in-line attribute is totally implementation
dependent, while built-in implies that the function has a special status in
the language.

For example, SIN is in fact expanded in-line by the Celerity FORTRAN
compiler. To use your personal SIN function you would have the either use an
EXTERNAL statement in the FORTRAN program (indicating that the identifier
SIN refers to a user function not the built-in) or explitly warn the
compiler through a command-line argument not the do the in-line expansion.

The selection of built-in functions that get expanded in-line is more a
reflection of the instruction set for which code is being generated than of
any inherent property of the function.
-- 
	ps
	(Pat Shanahan)
	uucp : {decvax!ucbvax || ihnp4 || philabs}!sdcsvax!celerity!ps
	arpa : sdcsvax!celerity!ps@nosc

dave@ur-helheim.UUCP (04/16/86)

In article <359@uvacs.UUCP> rwl@uvacs.UUCP (Ray Lubinsky) writes:
>> >C has standard built-in functions????
>> 
>> It looks like a function invocation, and is known and understood
>> by the compiler...
>
>The thing is, sizeof() evaluates to a constant *at run time*, just like
>'c'<<3  or  BUFSIZ  .  That makes it a pretty trivial function.  All it
>really does is give you a portable, automatic facility for referring to
>system dependencies.
>
>Ray Lubinsky	University of Virginia, Dept. of Computer Science

< *  italics mine * >

sizeof and BUFSIZ and a good implementation of  'c' << 3 resolve to 
constants at *compile time*.  No run time *evaluation* is necessary.



-- 
"The Faster I Go the Behinder I Get"
--Lewis Carroll

Dave Carlson

{allegra,seismo,decvax}!rochester!ur-valhalla!dave

mac@uvacs.UUCP (Alex Colvin) (04/18/86)

> > >C has standard built-in functions????
>   
> > Well, how about sizeof(foo)?

As has been pointed out, SIZEOF is not a function, it's an operator, like
"++".

Functions are often built-in in languages such as PASCAL, PL/I, FORTRAN,
etc. because they require special syntax (formats in the argument lists,
isubs) or information not kept at runtime (size of object, types of
arguments).  These must be wired in to the compiler.

C uses the fixed set of builtin operators for most of these cases.
Variable argument lists (printf), the typical sign of a built-in, are
handled otherwise in C.

See Algol68 for another language with operators but no need for BIFs.
Algol68's greatest success seems to be as an influence on C.

jlg@lanl.ARPA (Jim Giles) (04/19/86)

In article <149@diablo.ARPA> avg@diablo.UUCP (Allen VanGelder) writes:
>I think there may be a confusion in terminology between built-in and
>in-line.  In FORTRAN, MAX is expanded in-line, so you always get
>FORTRAN's MAX.  But SIN is not, and if you jiggle your libraries
>properly you will get your personal SIN function.  The same is true
>for READ and WRITE in FORTRAN.

Actually, you CAN get your own MAX function from Fortran.  All you do
is type :

      EXTERNAL MAX
      .
      .
      I=MAX(A)
	...

Then you provide your own MAX function in a library that's searched before
the system default library is searched.

Furthermore, you can declare MAX to be a local variable:

      REAL MAX(0:500)
	...

In fact, if you use MAX in a way that is not syntactically the same as a
function reference, Fortran will automatically declare a variable of the
appropriate type (subject to the requirements of the IMPLICIT statement).

	...
      MAX=5
	...

In Fortran, ALL identifiers can be redefined by the user (there are some
reserved keywords - they are too long to be identifiers, this will change
with 8x which allows 31 character identifiers).  It could be worse - it could
be PL-I with conditional expressions:

I=if if then then else else; /* or something like this! Bletch.


J. Giles
Los Alamos

joemu@nsc-pdc.UUCP (Joe Mueller) (04/21/86)

> > >C has standard built-in functions????
>   
> > Well, how about sizeof(foo)?
> > 
> > It looks like a function invocation, and is known and understood
> > by the compiler...
> 
> The thing is, sizeof() evaluates to a constant at run time, just like
> 'c'<<3  or  BUFSIZ  .  That makes it a pretty trivial function.  All it
> really does is give you a portable, automatic facility for referring to
> system dependencies.
> -- 

Sizeof is an operator, not a function. It's perfectly legal to say
"sizeof foo" (without the parens).

jlg@lanl.ARPA (Jim Giles) (04/25/86)

In article <562@nsc-pdc.UUCP> joemu@nsc-pdc.UUCP (Joe Mueller) writes:
>Sizeof is an operator, not a function. It's perfectly legal to say
>"sizeof foo" (without the parens).

An operator is a syntactic form that invokes a function!  SIZEOF is clearly
a function: it has a domain (actually two domains - data types and variables)
and it has a range (the non-negative integers) and it provides a mapping
from one to the other.  Since that is the mathematical definition of the
word 'function', it is clear that SIZEOF is one.  Now, it is true that
the syntactic description of C uses the term 'function' in a slightly
more restrictive way.  But the guy that wrote the syntactic description
of C just picked 'function' as a convenient name for a grammar rule.  If
you take it too literally, you will start saying absurd things like "'+'
is an operator and not a function."  Most people I know would be quite
surprised about that!

J. Giles
Los Alamos