我有 3 个文件依赖项,其中一个我实现了一个函数,您可以在下面看到第一个。它返回一个 32 位的 int 类型。第二个文件实现了一个调用第一个文件的函数的函数。该函数将从主文件(第三个文件)中调用。当我编译(使用 keil IDE)所有文件时,我有以下警告消息:
compiling App_Task_CAN.c...
..\src\Application_Tasks\App_Task_CAN.h(132): warning: #1295-D: Deprecated declaration App_Task_CAN_GetError - give arg types
uint32_t App_Task_CAN_GetError();
Run Code Online (Sandbox Code Playgroud)
这是我包含 stm32l4xx_hal_can.c 的文件中代码的一部分:
uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan)
{
return hcan->ErrorCode;
}
Run Code Online (Sandbox Code Playgroud)
其中 hcan 在 stm32l4xx_hal_can.ha 类型中:
/**
* @brief CAN handle Structure definition
*/
typedef struct
{
CAN_TypeDef *Instance; /*!< Register base address */
CAN_InitTypeDef Init; /*!< CAN required parameters */
CanTxMsgTypeDef* pTxMsg; /*!< Pointer to transmit structure */
CanRxMsgTypeDef* pRxMsg; /*!< Pointer to reception structure */
__IO …Run Code Online (Sandbox Code Playgroud) 我从VS2017工作赢得C++项目得到这个奇怪的行为:Intellisence丢失 - 我只是输入没有警告的纯文本,它仍然编译:
整个文件中没有显示错误.但是,当我在此函数范围之外的任何地方尝试相同的操作时,一切都按预期工作:
我的通用函数实现中出现问题:
#pragma region Public API
template <typename Key, typename Value>
void BinarySearchTree<Key, Value> ::Put(Key key, Value val)
{
Node node = root_;
if(node.key == null)
sadadasd
affsa
dasds
dasdsad
asdsad
}
#pragma endregion
Run Code Online (Sandbox Code Playgroud)
类定义如下:
template <typename Key, typename Value>
class BinarySearchTree {};
Run Code Online (Sandbox Code Playgroud)
它再次沉默 - 没有红/黄.编译的代码甚至运行.好像这部分被注释掉了.
尝试重装VS,没有帮助
c++ intellisense compilation compiler-warnings visual-studio-2017
正如预期的那样,对于以下程序,C/C++ 编译确实失败并显示“警告:指针和整数之间的比较”:
#include <stdbool.h>
int main(void) { return (int*)42 == true; }
Run Code Online (Sandbox Code Playgroud)
但是,当true文字更改为false. 为什么?
众所周知,局部变量具有局部范围和寿命.请考虑以下代码:
int* abc()
{
int m;
return(&m);
}
void main()
{
int* p=abc();
*p=32;
}
Run Code Online (Sandbox Code Playgroud)
这给了我一个函数返回局部变量地址的警告.我认为这是理由:一旦abc()完成,就会释放本地可验证的m.所以我们在主函数中解除引用无效的内存位置.
但是,请考虑以下代码:
int* abc()
{
int m;
return(&m);
int p=9;
}
void main()
{
int* p=abc();
*p=32;
}
Run Code Online (Sandbox Code Playgroud)
我在这里得到同样的警告.但我想m返回时仍会保留其生命周期.怎么了?请解释错误.我的理由是错的吗?
我有这个代码,有一些我不明白的东西
当我编译以下代码时:
#include <stdio.h>
#include <stdlib.h>
int main() {
double x=1;
double y=0;
if (x!=y)
{
printf("x!=y\n");
}
if (x=y)
{
printf("x=y\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下警告:警告:建议用作真值的赋值括号
当我运行程序时,我得到以下输出
x!=y
x=y
Run Code Online (Sandbox Code Playgroud)
为什么打印x = y如果'='不是要比较,而只是将值放在x中的y中.