Declarations with more/less detail, or "static" functins.

ORCUTT at cc.utah.edu ORCUTT at cc.utah.edu
Sun Aug 12 02:17:15 AEST 1990


I want to place a declaration for a static function at
the beginning of a file and define the function later
in the file.  What is the ANSI way to do this?  If I write

static void func(void);     /* Declaration. */

..

static void func(void)     /* Definition. */
{
..
return;
}

H & S seem to indicate that the first "static" is 
illegal.  If I remove it, the declaration will default
to type "extern", causing a conflict with the function definition.

In practice, MSC 5.1 and TC 2.0 and 3.0 allow the "static" on
the declaration.  If I omit the "static" on the definition,
these compilers will also declare the function "static" from
the previous declaration.  On the other hand, High-C follows
H & S more strictly in that it changes the "static" on the
declaration to "extern", with a warning.  However, High-C
allows the "static" on the definition to override the "extern"
assumed from the declaration, which also seems to be
non-standard behavior.

Is there an ANSI approved way to declare a function that
will be "static" in a file before it is defined?  This is
useful to that functions earlier in the file can reference
the function with the correct type of return value and
prototype.

The High-C way seems more in tune with the standard, which
states that a declaration can "add detail" to an earlier one;
but the High-C compiler prints about 5 lines of diagnostic
messages when it sees the "static" on the function definition,
although it does the right thing.

Does the standard allow one to make a declaration with
less detail of an object after it has been declared
with greater detail?  For example, are the declarations

double cos(double x);

and

double cos();

compatible?

Thanks for your attention to my ramblings...



More information about the Comp.std.c mailing list