有关夹板诊断的问题 [英] Question about a splint diagnostic

查看:38
本文介绍了有关夹板诊断的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个相同的文件,u1.c和u2.c只包含



typedef int Q;

我发出了splint u1.c u2.c。我得到了


u2.c:1:13:数据类型Q多次定义

重新定义函数或变量。其中一个声明应该是

使用

extern。 (使用-redef禁止警告)

u1.c:1:13:Q的先前定义

完成检查--- 1代码警告


这个警告是否合理?我认为typedef'有文件范围。


Spiros Bousbouras

I have two identical files , u1.c and u2.c which only contain
the line
typedef int Q ;
When I issue "splint u1.c u2.c" I get

u2.c:1:13: Datatype Q defined more than once
A function or variable is redefined. One of the declarations should
use
extern. (Use -redef to inhibit warning)
u1.c:1:13: Previous definition of Q

Finished checking --- 1 code warning

Is this warning justified ? I thought that typedef''s have file scope.

Spiros Bousbouras

推荐答案

sp****@gmail.com aécrit:
sp****@gmail.com a écrit :

我有两个相同的文件,u1.c和u2.c只包含



typedef int Q;

当我发出& ; splint u1.c u2.c"我得到了


u2.c:1:13:数据类型Q多次定义

重新定义函数或变量。其中一个声明应该是

使用

extern。 (使用-redef禁止警告)

u1.c:1:13:Q的先前定义

完成检查--- 1代码警告


这个警告是否合理?我认为typedef'有文件范围。


Spiros Bousbouras
I have two identical files , u1.c and u2.c which only contain
the line
typedef int Q ;
When I issue "splint u1.c u2.c" I get

u2.c:1:13: Datatype Q defined more than once
A function or variable is redefined. One of the declarations should
use
extern. (Use -redef to inhibit warning)
u1.c:1:13: Previous definition of Q

Finished checking --- 1 code warning

Is this warning justified ? I thought that typedef''s have file scope.

Spiros Bousbouras



typedef'有编译单元范围,好。但是,
splint很可能将此标记为错误,因为

相同类型的两个定义是灾难

等待发生...


如果它们不同,很难记住哪个是哪个

,这是一个不好的做法。


这当然是我的意见。


jacob

typedef''s have compilation unit scope, OK. BUT
splint flags this as an error very probably because
TWO definitions of the same type are a disaster
waiting to happen...

It is very difficult to remember which is which
if they are different, and it is a bad practice.

This is of course my opinion only.

jacob


jacob navia写道:
jacob navia wrote:
sp****@gmail.com aécrit:
sp****@gmail.com a écrit :

我有两个相同的文件,u1.c和u2.c只包含



typedef int Q;

当我发出splint u1.c u2.c时我得到了


u2.c:1:13:数据类型Q多次定义

重新定义函数或变量。其中一个声明应该是

使用

extern。 (使用-redef禁止警告)

u1.c:1:13:Q的先前定义

完成检查--- 1代码警告


这个警告是否合理?我认为typedef'有文件范围。


Spiros Bousbouras
I have two identical files , u1.c and u2.c which only contain
the line
typedef int Q ;
When I issue "splint u1.c u2.c" I get

u2.c:1:13: Datatype Q defined more than once
A function or variable is redefined. One of the declarations should
use
extern. (Use -redef to inhibit warning)
u1.c:1:13: Previous definition of Q

Finished checking --- 1 code warning

Is this warning justified ? I thought that typedef''s have file scope.

Spiros Bousbouras



typedef'有编译单元范围,好。但是,
splint很可能将此标记为错误,因为

相同类型的两个定义是灾难

等待发生...


如果它们不同,很难记住哪个是哪个是b $ b,这是一个不好的做法。


typedef''s have compilation unit scope, OK. BUT
splint flags this as an error very probably because
TWO definitions of the same type are a disaster
waiting to happen...

It is very difficult to remember which is which
if they are different, and it is a bad practice.



如何编写它以避免警告?在夹板''

建议之后我试过

typedef extern int Q;

在文件中u2.c夹板是可以的,但是lint给出了


(1)错误:只允许一个存储类

lint:u2.c中的错误;没有创建输出

lint:pass2 not run - u2.c中的错误


座右铭你不能讨好所有人对于代码检查实用程序来说似乎也是




让我解释一下我是如何第一次遇到这个问题的。

我是在自己的文件中写一个函数;让我们打电话

它foo.c该文件包含一个typedef。然后我写了

a短测试程序,test.c测试程序

当然需要相同的数据类型所以我把一个相同的

typedef里面test.c它编译得很好,但作为一个额外的

预防措施我也把它放在夹板上,那就是

我得到了关于定义相同数据类型的警告

不止一次。


这个函数将成为我自己库的一部分,我计划用
与多个一起使用它程式。

标准库函数的标题不包含extern下一个

到typedef,一个没有得到任何警告。我认为这是因为一个只与图书馆链接

而不是用一个人自己的程序编译它们。但是

我自己的库我倾向于选择更简单的选项

并且只需写一下

cc my-programme.c my-library。 c

而不是从my-library.c创建一个可链接的目标文件。

我不知道如何做到这一点。 />
所以如果我用

cc编译my-programme.c my-library.c

我也想写

splint my-programme.c my-library.c

并尽可能少地收到警告。据我所知

我有两个选择:

1)继续写夹板my-programme.c my-library.c

并接受当my-programme.c

从my-library.c复制typedef时我会收到警告

2)为我创建可链接的目标文件图书馆只与

链接。


我还有其他选择吗?


Spiros Bousbouras

How should I write it to avoid the warning ? Following splint''s
advice I tried
typedef extern int Q ;
in the file u2.c splint is ok with that but lint gives

(1) error: only one storage class allowed
lint: errors in u2.c; no output created
lint: pass2 not run - errors in u2.c

The motto "you can''t please everyone" seems to be
true for code checking utilities too !

Let me explain how I first encountered the problem.
I was writing a function in its own file ; let''s call
it foo.c The file included a typedef. Then I wrote
a short testing programme , test.c The test programme
needed of course the same datatype so I put an identical
typedef inside test.c It compiles fine but as an extra
precaution I also put it through splint and that''s when
I got the warning about the same datatype being defined
more than once.

This function will be part of my own library and I plan
to use it with more than one programmes. The headers of
standard library functions do not contain "extern" next
to typedef and one does not get any warnings. I take it
that this happens because one only links with the libraries
rather than compiling them with one''s own programme. But
with my own libraries I tend to go for the simpler option
and just write
cc my-programme.c my-library.c
rather than create a linkable object file from my-library.c
Off the top of my head I don''t even know how to do that.
So if I compile with
cc my-programme.c my-library.c
I also want to write
splint my-programme.c my-library.c
and get as little warnings as possible. As far as I can see
I have 2 options:
1) Continue to write splint my-programme.c my-library.c
and accept that I will get warnings when my-programme.c
duplicates the typedef''s from my-library.c
2) Create linkable object files for my libraries and only
link with those.

Is there another option that I''m missing ?

Spiros Bousbouras


sp **** @ gmail.com aécrit:
sp****@gmail.com a écrit :

jacob navia写道:

jacob navia wrote:


>> sp **** @ gmail.comaécrit:
>>sp****@gmail.com a écrit :

>>>我有两个相同的文件,u1.c和u2.c只包含

typedef int Q;
当我发出splint u1.c u2.c时我得到了

u2.c:1:13:数据类型Q定义了多次
重新定义了一个函数或变量。其中一个声明应该
使用
extern。 (使用-redef来禁止警告)
u1.c:1:13:Q的先前定义
完成检查--- 1代码警告

这是警告是否合理?我认为typedef'有文件范围。

Spiros Bousbouras
>>>I have two identical files , u1.c and u2.c which only contain
the line
typedef int Q ;
When I issue "splint u1.c u2.c" I get

u2.c:1:13: Datatype Q defined more than once
A function or variable is redefined. One of the declarations should
use
extern. (Use -redef to inhibit warning)
u1.c:1:13: Previous definition of Q

Finished checking --- 1 code warning

Is this warning justified ? I thought that typedef''s have file scope.

Spiros Bousbouras


typedef'有编译单元范围,好的。但是夹板很可能将此标记为错误,因为
同一类型的两个定义是等待发生的灾难...

这很难记住哪一个是哪个
如果它们不同,这是一个不好的做法。


typedef''s have compilation unit scope, OK. BUT
splint flags this as an error very probably because
TWO definitions of the same type are a disaster
waiting to happen...

It is very difficult to remember which is which
if they are different, and it is a bad practice.




如何编写它以避免警告?在夹板''

建议之后我试过

typedef extern int Q;

在文件中u2.c夹板是可以的,但是lint给出了


(1)错误:只允许一个存储类

lint:u2.c中的错误;没有创建输出

lint:pass2 not run - u2.c中的错误


座右铭你不能讨好所有人对于代码检查实用程序来说似乎也是




让我解释一下我是如何第一次遇到这个问题的。

我是在自己的文件中写一个函数;让我们打电话

它foo.c该文件包含一个typedef。然后我写了

a短测试程序,test.c测试程序

当然需要相同的数据类型所以我把一个相同的

typedef里面test.c它编译得很好,但作为一个额外的

预防措施我也把它放在夹板上,那就是

我得到了关于定义相同数据类型的警告

不止一次。


这个函数将成为我自己库的一部分,我计划用
与多个一起使用它程式。

标准库函数的标题不包含extern下一个

到typedef,一个没有得到任何警告。我认为这是因为一个只与图书馆链接

而不是用一个人自己的程序编译它们。但是

我自己的库我倾向于选择更简单的选项

并且只需写一下

cc my-programme.c my-library。 c

而不是从my-library.c创建一个可链接的目标文件。

我不知道如何做到这一点。 />
所以如果我用

cc编译my-programme.c my-library.c

我也想写

splint my-programme.c my-library.c

并尽可能少地收到警告。据我所知

我有两个选择:

1)继续写夹板my-programme.c my-library.c

并接受当my-programme.c

从my-library.c复制typedef时我会收到警告

2)为我创建可链接的目标文件图书馆只与

链接。


我还有其他选择吗?


Spiros Bousbouras



How should I write it to avoid the warning ? Following splint''s
advice I tried
typedef extern int Q ;
in the file u2.c splint is ok with that but lint gives

(1) error: only one storage class allowed
lint: errors in u2.c; no output created
lint: pass2 not run - errors in u2.c

The motto "you can''t please everyone" seems to be
true for code checking utilities too !

Let me explain how I first encountered the problem.
I was writing a function in its own file ; let''s call
it foo.c The file included a typedef. Then I wrote
a short testing programme , test.c The test programme
needed of course the same datatype so I put an identical
typedef inside test.c It compiles fine but as an extra
precaution I also put it through splint and that''s when
I got the warning about the same datatype being defined
more than once.

This function will be part of my own library and I plan
to use it with more than one programmes. The headers of
standard library functions do not contain "extern" next
to typedef and one does not get any warnings. I take it
that this happens because one only links with the libraries
rather than compiling them with one''s own programme. But
with my own libraries I tend to go for the simpler option
and just write
cc my-programme.c my-library.c
rather than create a linkable object file from my-library.c
Off the top of my head I don''t even know how to do that.
So if I compile with
cc my-programme.c my-library.c
I also want to write
splint my-programme.c my-library.c
and get as little warnings as possible. As far as I can see
I have 2 options:
1) Continue to write splint my-programme.c my-library.c
and accept that I will get warnings when my-programme.c
duplicates the typedef''s from my-library.c
2) Create linkable object files for my libraries and only
link with those.

Is there another option that I''m missing ?

Spiros Bousbouras



通常你将你的typedef放在一个公共的头文件中,比如

u2.h


然后,两个文件

#include" u2.h"

你只有一个定义就会产生同样的效果。


jacob

Normally you put your typedefs in a common header file like
u2.h

Then, both files
#include "u2.h"

and you have the same effect, with only ONE definition.

jacob


这篇关于有关夹板诊断的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆