static functions are functions that are only visable to other functions in the same file. Consider the following code.
main.c |
---|
#include |
funcs.c |
---|
/************************************* * * Function declarations (prototypes). * *************************************/ /* Func1 is only visable to functions in this file. */ static void Func1(void); /* Func2 is visable to all functions. */ void Func2(void); /************************************* * * Function definitions * *************************************/ void Func1(void) { puts("Func1 called"); } /*************************************/ void Func2(void) { puts("Func2 called"); } |
If you attempted to compile this code with the following command,
gcc main.c funcs.c |
it will fail with an error simular to.....
undefined reference to `Func1' |
Because 'Func1' is declared as static and cannot be 'seen' by 'main.c'.
For some reason, static has different meanings in in different contexts.
It seems a little strange that the same keyword has such different meanings....
C++ extensions for static
Top | Master Index | Keywords | Functions |
file: /Techref/language/ccpp/cref/SYNTAX/static.htm, 3KB, , updated: 2003/3/20 10:58, local time: 2024/8/22 06:10,
52.14.24.45:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://piclist.com/tecHREF/language/ccpp/cref/SYNTAX/static.htm"> static functions</A> |
Did you find what you needed? |
![]() o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
Welcome to piclist.com! |
.