Novice question.

Doug Gwyn gwyn at smoke.brl.mil
Thu Nov 15 02:40:26 AEST 1990


In article <3838 at vela.acs.oakland.edu> jmwojtal at vela.acs.oakland.edu (Wojo) writes:
>What exactly are the reasons "register" and "extrn" are used to declare
>values.  I see register alot in some of the programs and I don't know why
>they do it.  Is it just good practice or what.

"extern" is important in that it makes a declaration a reference to
something defined elsewhere; objects declared without extern at "file
scope" (outside of any function) constitute definitions, and there may
be but one definition per object among ALL the "translation units"
(source files, or corresponding object modules) constituting a complete
program.

"register" is just an efficiency hint to the compiler, requesting that
the object be assigned to "fast" storage such as a machine register.
Many modern compilers just ignore explicit "register" requests and
allocate storage as they deem fit.  My suggestion is to not use
"register" except when you've already tried everything else to speed
up the code and still need a smidgen more speed.

Undoubtedly these are explained in Kernighan & Ritchie's "The C
Programming Language" (either edition).



More information about the Comp.lang.c mailing list