portability

Doug Gwyn gwyn at smoke.BRL.MIL
Mon Jan 23 10:30:55 AEST 1989


In article <1989Jan20.055826.26116 at ziebmef.uucp> mdfreed at ziebmef.UUCP (Mark Freedman) writes:
>btw    I see that fstat() is not part of the ANSI stdio lib (unless I've missed
>something). How does one determine the length of a file in a portable fashion ?

No, fstat() was considered too much tailored to the UNIX environment for
inclusion in a system-independent language specification.  IEEE Std
1003.1 does specify it for POSIX environments.

The "length" of a file is a tricky notion in many implementations,
because it depends on how you count record structure overhead, padding,
etc.  The proposed ANSI C standard does specify that for a BINARY stream
(one fopened with the "b" mode modifier), ftell() returns the number of
bytes from the beginning of the file; therefore, you can use fopen(,"rb"),
fseek(,0L,SEEK_END), ftell(), and fclose() to implement a function that
returns the file's "length".  Just how useful that information will be
depends on what you plan to do with it; it may not be what you really
need to know.

>bbtw   As I recall, Microsoft implements the volatile keyword syntactically
>but not semantically.

Unless they perform hyper-optimization, they may not NEED to do anything
special in the case of "volatile".  All that "volatile" does is warn the
compiler that every access at that level of the type that is specified
by the source code for the "C virtual machine" must in fact occur in the
actual machine.  Unoptimized generated machine code would naturally do
that, and non-aggressive optimizations (such as Dennis originally put
into his PDP-11 compiler) would preserve this property.  It's when
registers start getting used intelligently to "cache" values that
optimizers tend to lose the natural volatile property of data objects.

Any essential USE of volatility is necessarily implementation-dependent,
so failure to implement it "right" cannot affect strictly-conforming
programs.  One presumes that if there is a reasonable use for volatility
then MicroSoft would provide some way to obtain the desired effect, even
if it requires use of "asm" (or better, _asm) or something else strange.



More information about the Comp.lang.c mailing list