Re: size of space to be allocated
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: size of space to be allocated         

Group: comp.lang.fortran · Group Profile
Author: David Thompson
Date: Aug 31, 2008 23:53

On Fri, 22 Aug 2008 00:23:58 GMT, "James Giles"
worldnet.att.net> wrote:
> glen herrmannsfeldt wrote:
>> In C, the sizeof operator (not function) works with either
>> types or variables. Often parentheses are needed, but it
>> still isn't a function.
>
> Of course, the distinction is hard to follow without formal
> definitions of the terms. In most language semantics discussions,
> an operator is just syntactic sugar for a function application.
>
And function notation can be sugar (or pepper?) for things I for one
think of as operators, e.g. SQRT() ABS() CMPLX(X,Y).
Or my probably all-time unfavorite, PL/I's SUBSTR().

But the formal difference is that operator symbols like + and && and
sizeof are reserved -- sizeof is a keyword -- and cannot be anything
else. Functions are 'just' named routines and those names can be
reused at least within (some) scopes. (Though standard C doesn't
guarantee you the ability to override a standard routine with your
own, as Fortran does if explicitly EXTERNAL, many implementations
support it just by linking your code before the library.)

In Fortran keywords aren't reserved, so this vanishes.
> I've got a copy of the C89 rationale document around here
> somewhere. I'm not sure it ever stated *why* sizeof is
> considered an operator. Though it may be that they wanted
> to allow types as operands, and didn't want to special-case
> their description of functions.
>
Very likely. Back in the early days, when as much as possible --
including all I/O, and nearly all string handling -- was sloughed off
into the library (and not recognized hence not optimized by the
compiler) to make the compiler work in perhaps 16KB on a PDP-11,
sizeof had to stay in the compiler. Not only can't you pass a type
itself as an arg at all, but you can't pass-by-value an arbitrary
(undescribed) type and expect an out-of-line function to deal with it.
> Parenthesis are optional only of the operand is a unary-expression.

Which is usually but not necessarily a (single) variable.
> It's probably good style to use parenthesis anyway.

Yeah. It's not like they cost $150 per barrel or something.

- formerly david.thompson1 || achar(64) || worldnet.att.net
no comments
diggit! del.icio.us! reddit!