C/C++语言标准当中,有没有所谓强符号,弱符号的感念?

pqepqeisd 2015-11-07 05:15:44
还是实现者的一种概念?

gcc编译c程序,未初始化的符号并没有成为弱符号啊
<<程序员的自我修养>>这本书上提到,对于gcc而言,程序中定义了但是没有初始化的符号就是弱符号,可以被强符号(定义并初始化)覆盖
于是做了一个实验:

$ cat x.c
int i=20;

$ cat main.c
#include<stdio.h>
int i;
int main()
{
printf("%d\n",i);
return 0;
}

却是是这样,而且这个仅对后缀名是.c的文件生效,.cpp就不起作用。
这个规则是gcc自己的呢,还是C/C++标准本身也提到了一些链接的规则?
谢谢。
...全文
181 1 打赏 收藏 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fefe82 2015-11-07
  • 打赏
  • 举报
回复
强符号 弱符号 不是 C 或 C++ 的概念。这是实现 C 或 C++ 的链接规则的一种实现。 C/C++ 标准将符号的链接属性分为三种,external linkage, internal linkage, no linkage。 不同编译单元(文件)中的具有 external linkage 的相同符号代表同一个对象。 具有 external linkage 的符号在同一个程序(program)(可以包含多个源文件)里,只能有一个 definition 。 ============== 但是,关于什么是 definition ,C 与 C++ 的不同叙述产生了不同的效果: C11 n1570 6.7 Declarations 5 A declaration specifies the interpretation and attributes of a set of identifiers. A definition of an identifier is a declaration for that identifier that: — for an object, causes storage to be reserved for that object; — for a function, includes the function body;119) — for an enumeration constant, is the (only) declaration of the identifier; — for a typedef name, is the first (or only) declaration of the identifier. C++14 n2496 3.1 Declarations and definitions 2 A declaration is a definition unless it declares a function without specifying the function’s body (8.4), it contains the extern specifier (7.1.1) or a linkage-specification25 (7.5) and neither an initializer nor a functionbody, it declares a static data member in a class definition (9.2, 9.4), it is a class name declaration (9.1), it is an opaque-enum-declaration (7.2), it is a template-parameter (14.1), it is a parameter-declaration (8.3.5) in a function declarator that is not the declarator of a function-definition, or it is a typedef declaration (7.1.3), an alias-declaration (7.1.3), a using-declaration (7.3.3), a static_assert-declaration (Clause 7), an attributedeclaration (Clause 7), an empty-declaration (Clause 7), a using-directive (7.3.4), an explicit instantiation declaration (14.7.2), or an explicit specialization (14.7.3) whose declaration is not a definition. int a; 在 C 里可能不是一个 definition (也可以是),但是在 C++ 里它一定是一个 definition 。 所以你的程序在 C 模式下可以编译,但是在 C++ 下就产生了重定义的错误。 ============== 猜想一下强符号 / 弱符号的作用: 在 C 里,编译器可以在不同文件的 int a; 的声明里任意选择一个作为定义,强符号/弱符号可以帮助编译器做出这一选择:强符号一定是一个定义,弱符号则可能不是一个定义。
附训练好的 YOLO 权重与 PyQt 可视化检测界面,页面底部含可视化效果预览,毕设/课设开箱即用。 【数据集概况】 · 检测类别(中文):[领航车(leader)] · 训练集:414 张 · 验证集:39 张 · 测试集:20 张 · 总计:473 张 该数据集聚焦于室内走廊环境中对领航车的精准识别与定位,具备高度场景专一性与实际应用价值。图像采集于光线均匀、结构规整的建筑内部通道,背景干扰因素少,有利于模型在复杂环境下的目标提取能力训练。领航车作为核心检测对象,在不同距离和角度下均被清晰标注,为智能导航系统、自动化引导设备等提供可靠的数据支持。... 【训练曲线与评估图】 【模型训练配置】 参数 | 值 模型 | yolo26n 训练轮数 | 100 epochs 输入尺寸 | 640x640 批次大小 | 24 优化器 | auto 初始学习率 | 0.01 训练设备 【关键指标汇总】 训练了 77 个 epoch,最终轮指标: 指标 | 数值 mAP50 | **0.9950** mAP50-95 | 0.9141 Precision | 0.9985 Recall | 1.0000 train/box_loss | 0.5224 train/cls_loss | 0.2526 val/box_loss | 0.4307 val/cls_loss | 0.1407 【训练过程分析】 77 轮训练后 mAP50 达到 0.9950,模型收敛良好。Loss 曲线前段快速下降,后段趋于平稳,val_loss 无反弹,没有明显过拟合。mAP50-95 为 0.9141,和 mAP50 差距仅 0.08,框的定位精度也很扎实。 【模型性能评估】 Precision 0.9985、Recall 1.000... 使用场景:毕业设计、课程设计、深度学习入门、工业场景落地验证。
内容概要:本文围绕基于序贯蒙特卡洛模拟法的配电网可靠性评估展开深入研究,提出并实现了结合Matlab的仿真方法,用于精确评估配电网在多种故障场景下的供电可靠性。研究充分考虑了元件故障、时序恢复过程及系统运行的随机性与动态性,采用序贯抽样技术模拟系统状态转移过程,实现了对停电频率、停电时间、供电可用率等关键可靠性指标的量化分析。文中系统阐述了算法的设计流程、事件抽样机制、状态序列生成逻辑以及系统恢复策略,并通过典型算例验证了该方法在复杂配电网络中的有效性与实用性,为配电网的规划、运行与优化提供了科学的评估工具。; 适合人群:具备电力系统分析基础和Matlab编程能力的高校研究生、科研人员,以及从事配电网规划设计、运行维护与可靠性管理的工程技术人员。; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的核心原理与实现方法;②学习利用Matlab构建配电网时序仿真模型,进行可靠性指标计算与分析;③为配电网的设备选型、网络结构优化、故障应对策略制定及韧性提升提供数据支撑与决策依据; 阅读建议:建议读者结合文中提供的Matlab代码实现步骤,动手复现实验过程,深入理解状态抽样、时序序列模拟、故障处理逻辑与指标统计等关键环节,并可进一步将该方法拓展应用于含分布式电源、储能系统等新型元件的现代复杂配电网可靠性评估研究。

65,214

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧