[sane-devel] General question on C programming

jazz_johnson at verizon.net jazz_johnson at verizon.net
Wed Oct 17 14:47:05 UTC 2007

I've been working on writing a driver (hs2p) for the Ricoh IS450/IS420 
scanners. I've drawn mainly from the bh and ibm drivers, but also a little 
from the avision and canon drivers.

My plan was to split the code into several parts:
hs2p.c            {sane_init(), sane_get_devices(), sane_open(), ...}
hs2p-scsi.c   {test_unit_ready(), scanner_inquiry(), set_window()...}
hs2p.h            {paper_sizes[], ...}
hs2p-scsi.h   {struct definitions for hs2p commands/data }

I have a question about the static keyword.
In bh.c nearly all functions are declared static which
as I understand it, limits the visibility of those function names to just 
bh.c, but since there is only 1 source file for the bh driver, this doesn't 
seem to do much, unless it also keeps other driver backends from seeing these 

The ibm driver {ibm.c and ibm-scsi.c} also declares most functions static:

static SANE_Status attach (const char *devnam, Ibm_Device ** devp)
...<What does the compiler see here?>
status = object_position (fd, OBJECT_POSITION_UNLOAD);

static SANE_Status object_position (int fd, int load)

So, is the static keyword necessary to prevent backend drivers from 
interfering with each other, or is the keyword unnecessary?

More information about the sane-devel mailing list