What is the scope of a function?

Discussion created by bigmac on Feb 8, 2012
Latest reply on Feb 27, 2012 by Daniel Lundin

Hello all,


I am using CW6.3 for HCS08 devices.


My project utilises the following two files (in addition to some other files):


// File:  SCI1.c#include "SCI.h"byte Rx_get_fifo( void);  // Fetch byte from receive buffer


// File:  SCI2.c#include "SCI.h"byte Rx_get_fifo( void);  // Fetch byte from receive buffer


The function Rx_get_fifo() is utilised from within each respective file only.  There is no declaration for Rx_get_fifo() within the header file.


My incorrect assumption was that the scope of the function would be limited to its own file.  However, the linker was unable to resolve, and indicated a naming conflict.


Solution 1:  Obviously, to use different function names.


Solution 2:  To declare each function as "static".  This seems unorthodox usage of the static keyword.  Most C textbooks refer this as a modifier for variables, but do not mention anything with respect to functions.


Perhaps someone will be able to explain why the function name did actually extend beyond file scope, without any extern declarations.  Additionally, are there any other side effects with using a "static" function?