ANSI C suggestions
Guy Harris
guy at rlgvax.UUCP
Fri Oct 19 08:02:30 AEST 1984
> > (1) Get rid of that requirement that all floating point arithmetic
> > be done in floating point. ...
>
> ... Note also that constants are still "double" unless explicitly cast
> to "float", which is a nuisance (the alternative was nightmarish problems
> in deciding the type of a floating-point constant). Not ideal, but workable.
I presume the FORTRAN alternative (it's single precision unless specified
with an exponent whose exponent character is 'd', not 'e', like
"3.1415926535d0") was rejected for compatibility reasons; intuiting the
type from the length of the string or somesuch is, I agree, nightmarish.
The only alternative is to require it to be stated explicitly somehow;
the question is whether the default should be "double" or "float". ("long"
constants already require the length to be specified explicitly, by a
trailing "L".)
> > (2) The DEC C compiler allows a "readonly" designation on global
> > variables. This is handy to insure that one does not overwrite
> > static lookup tables and such. ...
>
> Again the committee is ahead of you. There is a "const" modifier in the
> draft, taken from recent Bell-internal versions of C. It does more than
> you suggest -- in my opinion, more than is really necessary -- but it can
> be used to get this effect in particular. It is not just a convenience;
> people who are putting tables into ROM for micros need it badly.
And people who want to put tables or strings into shared code space, although
there you can get away with them being in non-shared and writable data space.
Currently, it's done with machine-dependent and implementation-dependent
kludges, usually called "rofix" (for shoving everything into text space by
turning ".data" into ".text" in the assembly output) or "yyfix" (for pushing
YACC tables into text space). The latter changes with the System V YACC,
as it depends on the exact shape of the generated "y.tab.c" to determine
what are parse tables (to be put into one source file) and what is everything
else (to be put into another source file).
"const" is long overdue; I'm considering dropping it into our C compilers
(although without the checking to catch attempts to modify constants at
compile time).
Guy Harris
{seismo,ihnp4,allegra}!rlgvax!guy
More information about the Comp.lang.c
mailing list