Re: structure initialization

Bob_Tracy (rct@gherkin.sa.wlk.com)
Sat, 29 Aug 1998 21:06:49 -0500 (CDT)


Doug Ledford wrote:
> Richard Gooch wrote:
>
> > So what is the difference between breaking all source and then
> > inserting NULLs, or appending the new method and taking advantage of
> > automatic structure initialisation.
>
> Automatic structure initing is damn sloppy coding in the kernel.

Why not use the scheme that the SCSI driver writers have been using
for some time? I don't know if it's part of ANSI C or a GNU C
extension, but it's a neat way to do things: you can associate
specific initializers with specific structure members in any order
you wish, and the powers that be can "diddle" the order of structure
members (as well as add new structure members -- *cough*) however they
deem fit and you don't get hosed. What this scheme *won't* protect you
from is someone changing the names of the structure members, but there
was bound to be a down side somewhere, eh? Here's an example from the
2.1.119 kernel (see drivers/scsi/aha1542.{c,h}):

Scsi_Host_Template driver_template = AHA1542;

#define AHA1542 { proc_dir: &proc_scsi_aha1542, \
name: "Adaptec 1542", \
detect: aha1542_detect, \
command: aha1542_command, \
queuecommand: aha1542_queuecommand, \
abort: aha1542_old_abort, \
reset: aha1542_old_reset, \
eh_abort_handler: aha1542_abort, \
eh_device_reset_handler: aha1542_dev_reset, \
eh_bus_reset_handler: aha1542_bus_reset, \
eh_host_reset_handler: aha1542_host_reset, \
bios_param: aha1542_biosparam, \
can_queue: AHA1542_MAILBOXES, \
this_id: 7, \
sg_tablesize: AHA1542_SCATTER, \
cmd_per_lun: AHA1542_CMDLUN, \
unchecked_isa_dma: 1, \
use_clustering: ENABLE_CLUSTERING, \
use_new_eh_code: 1}

-- 
Bob Tracy               |  "They couldn't hit an elephant at this dist- "
Firewall Security Corp. |   - Last words of Union General John Sedgwick,
rct@frus.com            |  Battle of Spotsylvania Court House, U.S. Civil War

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html