--- layout: fc_discuss_archives title: Message 147 from Frama-C-discuss on September 2013 ---
On Mon, Sep 30, 2013 at 5:35 PM, Virgile Prevosto <virgile.prevosto at m4x.org>wrote: > > * I have a variable "v" erroneously defined in two C files (a.c and > > b.c): what is the expected behaviour of a C compiler and Frama-C in > > such a case? > As often with the C standard, nothing is completely clear. (references > below are made against C99): > Following 6.2.2?5, and ?2, as long as v is not explicitely declared > static in one of the files, it should refer to the same object after > link. In addition, it should not be initialized explicitely in both > files (as per 6.9?5). > That said, 6.9.2?2 seems to indicate that if you only have int v; in a > file (without an explicit extern declaration), it should be treated as > int v = 0;, so that you would end up with a variable defined in both > a.c and b.c. > A quick check suggests that neither gcc nor clang does the latter: as > long as v is explicitely initialized in at most one file, they will > link the program and use this initializer, as does Frama-C. > This is a common compiler extension, listed as ?J.5.11 Multiple external definitions? in the standard itself. This was discussed in this StackOverflow question: http://stackoverflow.com/questions/1490693/tentative-definitions-in-c99-and-linking -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.gforge.inria.fr/pipermail/frama-c-discuss/attachments/20130930/f9dcbbd1/attachment.html>