[splint-discuss] how to satisfy splint on the " globalvariable" declaration.

Ken Raeburn raeburn at raeburn.org
Sat Sep 8 21:19:49 EDT 2007


On Sep 7, 2007, at 15:07, Michael Wojcik wrote:
>> From: splint-discuss-bounces at cs.virginia.edu
>> [mailto:splint-discuss-bounces at cs.virginia.edu] On Behalf Of
>> Ken Raeburn
>> Sent: Friday, 07 September, 2007 13:21
>>
>> Try declaring it in a header file that you include from both
>> source files.  Declare it there, and nowhere else.
>
> That produces undefined behavior. An object that is declared with
> external linkage, but never defined, is not guaranteed to exist:

Yes, sorry, you're correct.  I wasn't thinking about the definition  
(which technically includes a declaration as well).  There should be  
one "extern" declaration in one header that is seen everywhere, and  
one definition; for maximum type-checking, the extern declaration  
should be in scope where the definition is given, so that the  
compiler can check consistency between them.

(And the header file declaration should use "extern".  Omitting it  
causes use of "common" storage on some systems, but it's not a  
universal extension, and may result in multiple definitions in some  
implementations.)

Ken


More information about the splint-discuss mailing list