3

I have the following line of code:

ftDCB.ByteSize = FT_BITS_8;

And lint (PC-lint via Visual Lint, specifically) gives me a message 1924 on it ("C-style cast -- More Effective C++ #2").

FT_BITS_8 is #defined in a third party header file, and there's where the cast is:

#define FT_BITS_8           (UCHAR) 8

And UCHAR is a typedef from another third party header file:

typedef unsigned char UCHAR;

The thing it's being assigned to (ftDCB.ByteSize) is a BYTE, which is also a typedef for an unsigned char:

typedef unsigned char       BYTE;

I don't really want to modify the third-party headers, so I tried to suppress the message in my code:

//lint -e(1924) C-style cast
ftDCB.ByteSize = FT_BITS_8;

But I get the same 1924 message.

What am I doing wrong here? And is there a cleaner way to do what I want to accomplish (other than modifying the third-party header)?

4

3 回答 3

4

好的,回答我自己的问题,以下似乎可行:

ftDCB.ByteSize = /*lint -e(1924) C-style cast */ FT_BITS_8;
于 2014-05-22T16:00:24.953 回答
3

我刚刚遇到了同样的问题,我找到了一个更好的方法来解决这个问题(记住代码可读性是代码质量的一个主要方面,如果它被 lint 注释乱七八糟,那就很丑了)。

因此,如果为您提供了一个无法更改的标头(例如微控制器中的外围设备定义),您应该以某种方式包含它们,以便 PC-lint 知道它是一个库标头。有几种方法,最简单的可能是使用尖括号。

所以而不是:

#include "peripheral.h"

利用:

#include <peripheral.h>

这将告诉 PC-lint 将该文件视为库头,这使您可以更好地控制使用-elib和它的兄弟的消息。

如果您的消息基于宏,则-elibmacro提供了一个很好的可能性:

//lint -save
//lint -elibmacro(1924)
#include <peripheral.h>
//lint +elibmacro(1924)
//lint -restore

这将阻止消息 1924 来自其中定义peripheral.h并包含的所有宏。

-save和可能是多余的-restore,但这是我的一种习惯,因为我经常遇到麻烦,一次禁用很多功能并且不再收到任何消息。

请注意,现在包含的所有头文件都peripheral.h将被视为库头文件,但您通常希望这样做。

您可能想阅读有关库的 PC-lint 手册第 6 章。

于 2015-01-20T15:18:46.830 回答
0

由于 FT_BITS_8 是一个宏,因此-esym(1924,FT_BITS_8)您的 std.lnt 文件中的 也将删除此问题的所有实例。

于 2014-07-09T01:39:23.193 回答