我刚刚在我的嵌入式项目中下载了带有 c++20 的 GCC 10。
然而,在嵌入式应用程序中,寄存器结构映射器使用 volatile 是很常见的。
由于编译器不知道寄存器值是否被 DMA 从外部更改,因此“强制”重新加载该寄存器是有意义的。
为了提高性能,其中一些 volatiles 被放置在 C 头文件中。当我在 cpp 文件中包含这些头文件时,我会收到很多不稳定的弃用错误。
有什么办法可以禁用这些错误吗?
@Edit 根据要求提供一些示例代码。
/*!
* @brief Enable the clock for specific IP.
*
* @param name Which clock to enable, see \ref clock_ip_name_t.
*/
static inline void CLOCK_EnableClock(clock_ip_name_t name)
{
uint32_t regAddr = SIM_BASE + CLK_GATE_ABSTRACT_REG_OFFSET((uint32_t)name);
(*(volatile uint32_t *)regAddr) |= (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT((uint32_t)name));
}
Run Code Online (Sandbox Code Playgroud)
C:/xxx/kinetisSDK/2.7.0/devices/MK64F12/drivers/fsl_clock.h:671:37: error: compound assignment with 'volatile'-qualified left operand is deprecated [- Werror=volatile]
671 | (*(volatile uint32_t *)regAddr) |= …Run Code Online (Sandbox Code Playgroud) Hey I'm trying to design some Interfaces without any runtime overhead using c++20 concepts.
I came up with the following (simplified) concept
/**
* @brief This concept defines an OSA Interface
*/
template<typename T, typename Task_T>
concept OSA_Layer_T = requires (T a) {
{T::getName(a)} -> std::same_as<std::string>; ///< Returns the name of the task (if no name is available return the ID as string)
{T::getId(a)} ->std::same_as<Task_T>; ///< returns the (underlying) ID of the task
};
Run Code Online (Sandbox Code Playgroud)
Since every OS has it's own …
我正在我的代码上运行 MSVC 的静态分析器,并且收到无法解决的警告。我不确定这是否是误报,希望您能帮助我解决这个问题。我正在使用 MSVC17。
void GetParam_MEASLIST(Message* pMsgReturn)
{
pMsgReturn->u8MessageType = MESSAGE_FAILED;
uint32_t u32ChannelCount = 0;
u32ChannelCount = ChannelHandler_getChannelCount();
if (u32ChannelCount == 0)
{
return;
}
char** szStringList = (char**)malloc(u32ChannelCount * sizeof(char*));
if (NULL == szStringList)
{
return;
}
for (uint32_t i = 0; i < u32ChannelCount; ++i)
{
ChannelInfo_t tmp = { 0 };
if (!ChannelHandler_getChannelInfo(i, &tmp))
{
LOG_ERROR("Failed to get channel info for channel %i", mg_strLogCat, 10);
}
else
{
size_t nSize = strlen(tmp.ChannelDeviceInfo.szMeasType) + 1;
if (nSize > …Run Code Online (Sandbox Code Playgroud) 我正在使用嵌入式模板化库 etl::queue
https://www.etlcpp.com/queue.html
在etl::queueIS quitvalent到std::queue
为了避免复制,我想将元素实际移动到队列中。
现在我的设置看起来像这样
bool CETLConcurrentQueue<ElementType_T, u32QueueSize>::Add(ElementType_T &&element, const uint32_t u32Timeout)
{
//lock mutex...
queue.push(element);
//do further stuff
}
Run Code Online (Sandbox Code Playgroud)
现在我不使用了,queue.push(std::move(element));因为 element 已经是一个右值引用了
但是,queue.push(element);调用元素复制构造函数(已删除)如何改为调用元素移动构造函数?