当非静态函数声明跟在静态函数声明之后会发生什么?

编程入门 行业动态 更新时间:2024-10-10 06:17:37
本文介绍了当非静态函数声明跟在静态函数声明之后会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以下编译:

static int foo() { return 1; } int foo();

但是,它将始终编译吗?在这种情况下,行为是否定义明确?当非静态原型遵循静态声明时,这意味着什么?

But, will it always compile? Is the behavior in this case well defined? And what does it means when a non-static prototype follows a static declaration?

推荐答案

是的,它将进行编译并且行为已明确定义.由于foo在int foo(); 1 之前声明为static,因此foo具有内部链接.

Yes it will compile and behavior is well defined. Since foo is declared static earlier than int foo();1, foo has internal linkage.

对于在可见该标识符的先前声明的范围内用存储类说明符extern声明的标识符, 31) (如果该先前声明指定了内部或外部)关联,则后面的声明中标识符的链接与先前声明中指定的链接相同. [...]

For an identifier declared with the storage-class specifier extern in a scope in which a prior declaration of that identifier is visible,31) if the prior declaration specifies internal or external linkage, the linkage of the identifier at the later declaration is the same as the linkage specified at the prior declaration. [...]

和脚注指出:

31)按照6.2.1的规定,后面的声明可能会隐藏前面的声明.

31) As specified in 6.2.1, the later declaration might hide the prior declaration.

1 .如果未指定存储类别,则假定该函数具有外部链接.标准说:如果函数标识符的声明没有存储类说明符,则其链接 完全确定是否与存储类说明符extern-6.2.2(p5)声明的一样.

1. If no storage class is specified , the function is assumed to have external linkage. Standard says: If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier extern -- 6.2.2 (p5).

更多推荐

当非静态函数声明跟在静态函数声明之后会发生什么?

本文发布于:2023-10-31 06:44:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545328.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   函数   声明   后会   跟在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!