小编JHe*_*eni的帖子

c++20 中是否不推荐使用 volatile 限定符?

我刚刚在我的嵌入式项目中下载了带有 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)

c++ embedded gcc c++20

4
推荐指数
1
解决办法
515
查看次数

C++20 concepts as Interfaces

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 …

c++ c++-concepts c++20

2
推荐指数
1
解决办法
737
查看次数

静态分析仪误报?

我正在我的代码上运行 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)

c

2
推荐指数
1
解决办法
76
查看次数

c ++如何将右值引用传递给另一个函数

我正在使用嵌入式模板化库 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);调用元素复制构造函数(已删除)如何改为调用元素移动构造函数?

c++ move-constructor move-semantics c++11

1
推荐指数
1
解决办法
166
查看次数

标签 统计

c++ ×3

c++20 ×2

c ×1

c++-concepts ×1

c++11 ×1

embedded ×1

gcc ×1

move-constructor ×1

move-semantics ×1