JavaScript is required to for searching.
跳过导航链接
退出打印视图
Oracle Solaris Studio 12.3:C 用户指南     Oracle Solaris Studio 12.3 Information Library (简体中文)
search filter icon
search icon

文档信息

前言

1.  C 编译器介绍

2.  特定于 C 编译器实现的信息

3.  并行化 C 代码

4.  lint 源代码检验器

4.1 基本和增强 lint 模式

4.2 使用 lint

4.3 lint 命令行选项

4.3.1 -#

4.3.2 -###

4.3.3 -a

4.3.4 -b

4.3.5 -C filename

4.3.6 -c

4.3.7 -dirout=dir

4.3.8 -err=warn

4.3.9 -errchk=l(, l)

4.3.10 -errfmt=f

4.3.11 -errhdr=h

4.3.12 -erroff=tag(, tag)

4.3.13 -errsecurity=level

4.3.14 -errtags=a

4.3.15 -errwarn=t

4.3.16 -F

4.3.17 -fd

4.3.18 -flagsrc=file

4.3.19 -h

4.3.20 -Idir

4.3.21 -k

4.3.22 -Ldir

4.3.23 -lx

4.3.24 -m

4.3.25 -m32|-m64

4.3.26 -Ncheck=c

4.3.27 -Nlevel=n

4.3.27.1 -Nlevel=1

4.3.27.2 -Nlevel=2

4.3.27.3 -Nlevel=3

4.3.27.4 -Nlevel=4

4.3.28 -n

4.3.29 -ox

4.3.30 -p

4.3.31 -Rfile

4.3.32 -s

4.3.33 -u

4.3.34 -V

4.3.35 -v

4.3.36 -Wfile

4.3.37 -XCC=a

4.3.38 -Xalias_level[=l ]

4.3.39 -Xarch=amd64

4.3.40 -Xarch=v9

4.3.41 -Xc99[= o]

4.3.42 -Xkeeptmp=a

4.3.43 -Xtemp=dir

4.3.44 -Xtime=a

4.3.45 -Xtransition=a

4.3.46 -Xustr={ascii_utf16_ushort| no}

4.3.47 -x

4.3.48 -y

4.4 lint 消息

4.4.1 用于禁止消息的选项

4.4.2 lint 消息格式

4.5 lint 指令

4.5.1 预定义值

4.5.2 指令

4.6 lint 参考和示例

4.6.1 由 lint 执行的诊断

4.6.1.1 一致性检查

4.6.1.2 可移植性检查

4.6.1.3 可疑的构造

4.6.2 lint

4.6.3 lint 过滤器

5.  基于类型的别名分析

6.  转换为 ISO C

7.  转换应用程序以适用于 64 位环境

8.  cscope:交互检查 C 程序

A.  按功能分组的编译器选项

B.  C 编译器选项参考

C.  实现定义的 ISO/IEC C99 行为

D.  C99 的功能

E.  实现定义的 ISO/IEC C90 行为

F.  ISO C 数据表示法

G.  性能调节

H.  Oracle Solaris Studio C:K&R C 与 ISO C 之间的差异

索引

4.4 lint 消息

lint 的大多数消息都很简单,对于它们诊断的每个问题都输出一行语句。对于包含的文件中检测到的错误,编译器会报告多次,而 lint 仅报告一次(无论其他源文件中包含该文件多少次)。文件之间存在不一致时会发出复合消息,并且在少数情况下,文件内部存在问题时也会发出复合消息。单个消息描述所检查的文件中的各个问题。如果使用 lint 过滤器要求对出现的每个问题都输出一条消息,可通过调用带有 -s 选项的 lint 将复合诊断转换为简单类型。有关更多信息,请参见4.6.2 lint

lint 的消息会写入 stderr

4.4.1 用于禁止消息的选项

可以使用几个 lint 选项禁止 lint 诊断消息。可以使用后跟一个或多个 tag-erroff 选项禁止消息。可以使用 -errtags=yes 选项显示这些助记符标记。

下表列出了用于禁止 lint 消息的选项。

表 4-8 用于禁止消息的 lint 选项

选项
禁止的消息
-a
assignment causes implicit narrowing conversion

conversion to larger integral type may sign-extend incorrectly

-b
statement not reached (unreachable break and empty statements)
-h
assignment operator "=" found where equality operator "==" was expected

constant operand to op: "!"

fallthrough on case statements

pointer cast may result in improper alignment

precedence confusion possible; parenthesize

statement has no consequent: if

statement has no consequent: else

-m
declared global, could be static
-erroff=tag
tag 指定的一条或多条 lint 消息
-u
name defined but never used

name used but not defined

-v
arguments unused in function
-x
name declared but never used or defined

4.4.2 lint 消息格式

通过某些选项,lint 程序可以显示精确的源文件行以及指向发生错误的行所在位置的指针。启用此功能的选项为 -errfmt=f,将使 lint 提供以下信息:

例如,以下程序 Test1.c 包含一个错误。

1 #include <string.h>
2 static void cpv(char *s, char* v, unsigned n)
3 { int i;
4   for (i=0; i<=n; i++){
5        *v++ = *s++;}
6 }
7 void main(int argc, char* argv[])
8 {
9     if (argc != 0){
10        cpv(argv[0], argc, strlen(argv[0]));}
11}

Test1.c 中使用带 —errfmt=src 选项的 lint 将生成以下输出:

% lint -errfmt=src -Nlevel=2 Test1.c
      |static void cpv(char *s, char* v, unsigned n)
      |            ^  line 2, Test1.c
      |
      |         cpv(argv[0], argc, strlen(argv[0]));
      |                      ^  line 10, Test1.c
warning: improper pointer/integer combination: arg #2
      |
      |static void cpv(char *s, char* v, unsigned n)
      |                               ^  line 2, Test1.c
      |
      |cpv(argv[0], argc, strlen(argv[0]));
      |                       ^ line 10, Test1.c
      |
      |        *v++ = *s++;
      |         ^  line 5, Test1.c
warning:use of a pointer produced in a questionable way
    v defined at Test1.c(2)    ::Test1.c(5)
      call stack:
          main()                ,    Test1.c(10)
          cpv()                 ,    Test1.c(5)

第一个警告指示互相矛盾的两个源代码行。第二个警告显示调用堆栈以及导致错误的控制流。

另一个程序 Test2.c 包含一个不同的错误:

1 #define AA(b) AR[b+l]
2 #define B(c,d) c+AA(d)
3
4 int x=0;
5
6 int AR[10]={1,2,3,4,5,6,77,88,99,0};
7
8 main()
9  {
10  int y=-5, z=5;
11  return B(y,z);
12 }

Test2.c 中使用带 —errfmt=macro 选项的 lint 将生成以下输出,并显示宏替换的步骤:

% lint -errfmt=macro Test2.c
      | return B(y,z);
      |        ^  line 11, Test2.c
      |
      |#define B(c,d) c+AA(d)
      |                 ^  line 2, Test2.c
      |
      |#define AA(b) AR[b+l]
      |                   ^  line 1, Test2.c
error: undefined symbol: l
|
      |    return B(y,z);
      |           ^  line 11, Test2.c
      |
      |#define B(c,d) c+AA(d)
      |                 ^  line 2, Test2.c
      |
      |#define AA(b) AR[b+l]
      |                   ^  line 1, Test2.c
variable may be used before set: l
lint: errors in Test2.c; no output created
lint: pass2 not run - errors in Test2.c