linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* does static function declaration require static definition?
@ 2005-08-02 19:23 Robert P. J. Day
  2005-08-03  8:04 ` Steve Graegert
  0 siblings, 1 reply; 2+ messages in thread
From: Robert P. J. Day @ 2005-08-02 19:23 UTC (permalink / raw)
  To: C programming list


  from my 5th edition of harbison and steele, p. 83, i read that the
"static" storage class specifier on a function "indicates that the
declared function will be defined -- with storage class static --
later in the file."

  doesn't this read that, once you declare the function as static, you
*must* define it as static as well?  gcc doesn't seem to have a
problem with leaving "static" off of the definition.

  of course, gcc certainly complains if you forget the "static" on the
declaration but put it on the definition further down.

rday

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: does static function declaration require static definition?
  2005-08-02 19:23 does static function declaration require static definition? Robert P. J. Day
@ 2005-08-03  8:04 ` Steve Graegert
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Graegert @ 2005-08-03  8:04 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: C programming list

On 8/2/05, Robert P. J. Day <rpjday@mindspring.com> wrote:
> 
>  from my 5th edition of harbison and steele, p. 83, i read that the
> "static" storage class specifier on a function "indicates that the
> declared function will be defined -- with storage class static --
> later in the file."
> 
>  doesn't this read that, once you declare the function as static, you
> *must* define it as static as well?  gcc doesn't seem to have a
> problem with leaving "static" off of the definition.

For GCC it should be sufficient to declare a function as static and
omit the static keyword in the definition (but I prefer to see it in
both, declarations and definitions):

	/* declaration */
	static void func(int, int);
	
	/* definition */
	void func(int a, int b) {
		/* do some work here */
	}

Please note that static functions are only visible to other functions
in the same translation unit.  Also note that C99 (p. 141 §4) says:

"The storage-class specifier, if any, in the declaration specifiers
shall be either extern or static."

The static keyword is optional in function definitions.

Regards

       \Steve
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-08-03  8:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-02 19:23 does static function declaration require static definition? Robert P. J. Day
2005-08-03  8:04 ` Steve Graegert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).