section ("section-name")

本文介绍如何在程序中使用section属性来指定全局变量位于特定部分,包括初始化定义和注意事项,以及某些文件格式不支持任意部分的情况。

Normally, the compiler places the objects it generates in sections like data and bss. Sometimes, however, you need additional sections, or you need certain particular variables to appear in special sections, for example to map to special hardware. The section attribute specifies that a variable (or function) lives in a particular section. For example, this small program uses several specific section names:

              struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };
              struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };
              char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };
              int init_data __attribute__ ((section ("INITDATA"))) = 0;
              
              main()
              {
                /* Initialize stack pointer */
                init_sp (stack + sizeof (stack));
              
                /* Initialize initialized data */
                memcpy (&init_data, &data, &edata - &data);
              
                /* Turn on the serial ports */
                init_duart (&a);
                init_duart (&b);
              }
         

    Use the section attribute with an initialized definition of a global variable, as shown in the example. GCC issues a warning and otherwise ignores the section attribute in uninitialized variable declarations.

    You may only use the section attribute with a fully initialized global definition because of the way linkers work. The linker requires each object be defined once, with the exception that uninitialized variables tentatively go in the common (or bss) section and can be multiply “defined”. You can force a variable to be initialized with the -fno-common flag or the nocommon attribute.

    Some file formats do not support arbitrary sections so the section attribute is not available on all platforms. If you need to map the entire contents of a module to a particular section, consider using the facilities of the linker instead.

 

原文见:http://mcuos.com/archiver/tid-2780.html

你已经为 `.name-box` 设置了 `width: 160px` 和 `overflow: hidden`,但要实现 **文本超长时显示省略号(...)**,并且 **鼠标悬浮时完整显示内容(通过 title 或 tooltip)**,还需要补充几个关键的 CSS 属性。 --- ### ✅ 正确实现:单行文本超长省略 + 悬浮提示 #### ✅ 1. 完整 CSS 样式 ```css .info-section .name-box { width: 160px; overflow: hidden; text-overflow: ellipsis; /* 关键:显示省略号 */ white-space: nowrap; /* 关键:禁止换行 */ /* 可选:防止弹性布局拉伸 */ min-width: 0; } ``` > 🔍 解释: > - `white-space: nowrap`:强制文本在一行内显示 > - `text-overflow: ellipsis`:溢出部分用 `...` 表示 > - `overflow: hidden`:隐藏溢出内容 --- #### ✅ 2. React JSX 代码(自动显示 title) 只需确保 `<Typography>` 渲染的是纯文本,浏览器会自动将 `title` 显示为悬浮提示: ```jsx <Box className="name-box" title={mockItem.name}> <Typography>{mockItem.name}</Typography> </Box> ``` > ✅ 效果: > - 文本过长 → 显示为 `这是一个很长的名字...` > - 鼠标悬停 → 浏览器原生 tooltip 显示完整名字 --- ### 🛠️ 进阶方案:使用 Tooltip 组件(更美观) 如果你使用的是 **Material-UI (MUI)**,推荐用 `<Tooltip>` 实现更漂亮的提示框。 #### 示例(MUI v5): ```jsx import { Box, Typography, Tooltip } from '@mui/material'; <Tooltip title={mockItem.name} arrow placement="top"> <Box className="name-box"> <Typography>{mockItem.name}</Typography> </Box> </Tooltip> ``` > ✅ 优点: > - 更美观的样式 > - 支持 `arrow` 箭头、`placement` 定位 > - 可自定义延迟、动画等 --- ### 💡 注意事项 | 问题 | 解决方法 | |------|----------| | 省略号不生效 | 必须同时设置 `white-space: nowrap` 和 `text-overflow: ellipsis` | | Flex 布局中宽度失效 | 给父容器或 `.name-box` 加 `min-width: 0` | | 中文断字异常 | `word-break: keep-all`(中文不拆字) | #### 增强版 CSS(防 Flex 拉伸): ```css .info-section .name-box { width: 160px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; /* 在 flex 或 grid 中很重要 */ } ``` --- ### 🧪 测试建议 你可以临时添加一段超长名字测试: ```js const mockItem = { name: "这是一个非常非常非常非常非常长的名字" }; ``` 看是否正常显示省略号,并且悬停能查看全部。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值