Reputation: 1211
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)?
Upvotes: 3
Views: 12856
Reputation: 362
I just had the same issue, and I found a nicer way to fix this (remember code readability is a main aspect of code quality and if it gets littered with lint comments, it's quite ugly).
So if you are provided with a header you cannot change (like peripheral definitions in microcontrollers), you should include them in a way, so that PC-lint knows it's a library header. There are several ways, the easiest is probably to use angle brackets.
So instead of:
#include "peripheral.h"
Use:
#include <peripheral.h>
This will tell PC-lint to treat the file as library header, which gives you access to finer control over messages using -elib
and it's brothers.
If your messages are based on a macro, the -elibmacro
provides a nice possibility:
//lint -save
//lint -elibmacro(1924)
#include <peripheral.h>
//lint +elibmacro(1924)
//lint -restore
This will block message 1924 coming from all macros defined in peripheral.h
and includes from there.
The -save
and -restore
are probably superfluous, but it's a habit of mine as I got into trouble often enough with disabling to much at one point and not getting any messages any more.
Note, that all headers included in peripheral.h
will be treated as library headers now, but you usually want that.
You may want to read the PC-lint manual chapter 6 concerning libraries.
Upvotes: 3
Reputation: 26068
As FT_BITS_8 is a macro, the -esym(1924,FT_BITS_8)
in your std.lnt file would also remove all instances of this issue.
Upvotes: 0
Reputation: 1211
OK, answering my own question, the following seems to work:
ftDCB.ByteSize = /*lint -e(1924) C-style cast */ FT_BITS_8;
Upvotes: 4