| | |
What is Static functions
![]() |
A static function is a function with the static qualifier applied:
What it does is restrict visibility of the function to the translation unit in which it's declared. Functions are implicitly declared as extern by default, which means they're visible across translation units. You can compile the following, but it won't link:
C Syntax (Toggle Plain Text)
static void foo ( void ) { /* Blah blah */ }
C Syntax (Toggle Plain Text)
/* file1.c */ void foo ( void ) { } extern void bar ( void ) { } static void baz ( void ) { }
C Syntax (Toggle Plain Text)
/* file2.c */ void foo ( void ); void bar ( void ); void baz ( void ); int main ( void ) { foo(); /* OK: foo is extern by default */ bar(); /* OK: bar is explicitly extern */ baz(); /* Wrong: baz isn't visible in this translation unit */ }
Last edited by Narue; Jul 3rd, 2007 at 4:28 pm.
In case you were wondering, yes, I do hate you.
![]() |
Similar Threads
- Static virtual functions - Reasons (C++)
- static function (C)
- What is Static Friend function (C)
- static friend function (C)
- C++ reading,writing,displaying a file? (C++)
- Practical application of static member function (C++)
- accessing private data members (C++)
Other Threads in the C Forum
- Previous Thread: Float/Double to String conversion
- Next Thread: polynomial ADT
Views: 27328 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C
ansi api array arrays asterisks binarysearch c++ calculate centimeter char convert copyimagefile cprogramme data database dice directory dynamic error evaluation fflush fgetc file fork function functions getlasterror givemetehcodez grade graphics hacking hardware homework inches incrementoperators input km lazy library linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix microsoft motherboard mysql no-code no-effort number opendocumentformat opensource output owf parallel pattern pdf performance pointer pointers posix precedence problem probleminc program programing programming read recursion recursive recv scanf scripting segmentationfault sms_speak socketprograming spoonfeeding standard string strings strtok structures student syntax system systemcall turbo-c turboc unix user variable visual voidmain() wab windows words






