c - Accordance of linkage between declaration and definition -


I'm thinking that there is a snippet below, in which the definition of f fails to repeat The f is the static link, that's right:

  Fixed int f (int); Int f (int x) {return x; }   

Rubbing does not emit any warning for this. Without answering my question, I have read section 6.7.1 of the C11 standard.

For example, it is possible to imagine more questions in the same vein, for example below t1.c and t2.c, and it would be nice if some of these answers are normally applied Yes, but I'm only concerned about the first example above.

  ~ $ cat t1.c fixed int f (int); Int f (int); Int f (int x) {return x; } ~ $ Clang -c -std = c99 -pedantic t1.c ~ $ nm t1.o WARNING: /Applications/Xcode.app/aername/bin/nm: A name list ~ $ cat t2.c int f (int) ; Fixed int F (int); Int f (int x) {return x; } ~ $ Clang -c -std = c99 -pedantic t2.c t2.c: 3: 12: Error: The steady declaration of 'F' is non-static declaration according to the constant constant f (int); ^ T2C: 1: 5: Note: The previous announcement here is int (int); ^ 1 error occurred. The rules of the linkage are a bit misleading, and it is different for work and objects.  

In essence, the rules are as follows:

  • The first declaration determines the relationship.
  • Static means internal relation.
  • extern means that has already been announced, if no one has been declared, external.
  • If none of them is given, then it is like extern for the function, and external linkage for the object identifier (with a definition in the same translation unit) .

    So, it is valid:

      Fixed Intel F (int); // f linking is int int (int); // External Intel F like the next line; // First declaration in the form of linking, thus the internal int f (int x) {return x; }   

    On the other hand, the undefined behavior (CF111 (n1570) 6.2.2 p7) is:

      int f (int); // As soon as the extartor was given, no announcement is being seen, // Therefore linking is external; static int F (int); // UB, has already been declared with external relation. Int f (int x) {return x; } // If any of the above // ​​announcements were deleted then it would be OK.   

    Most of these are included in C11 6.2.2. From the N1570 draft:

    (3) If the declaration of a file scope identifier for an object or function is in the storage-category specification stable , then the identifier internal relationship

    (4) For an archive declared in an identification with the storage-category specification extern in which a pre-declaration of that identifier Show <31> , if the first declaration specifies internal or external relations, then b Link identifier declared in the same link as specified in the same announcement. If no prior declaration is shown, or if the pre-declaration does not specify a relationship, the identifier has an external connection.

    (5) If there is no storage category specification in the declaration of an identifier for a function, then the linkage is fixed as if it is the storage-class specification extern was declared with. If the declaration of an identifier for an object is a file scope and there is no storage-class specifier, its linkage is external.

    30) Storage class specifier in a function manifesto only then this file is in the scope; See 6.7.1.
    31) As is specified in 6.2.1, the announcement can later hide the first declaration.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -