什么是正确的警告/错误? [英] What would be the right warning/error?

查看:113
本文介绍了什么是正确的警告/错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这段代码


static typedef struct {

int boo;

} FOO;


这与MSVC激起:

------------------------------

Microsoft(R)C / C ++优化编译器版本14.00.50727.762(适用于x64)


tstruct.c

tstruct.c(1):错误C2159:指定多个存储类

------------------------------


有了gcc,我们有:

----------------------------

root @ ubuntu-vm:/ tmp #gcc tc

tc:1:错误:声明说明符中的多个存储类

------------------- ---------


凭借lcc-win我有

警告tstruct.c:声明中有多种类型。最后将使用

:''typedef''


with lcc-win64

-------- ----------------------

警告tstruct.c:1多次使用''typedef''

------------------------------


所有这些警告都具有误导性我的看法。我已经改变了

的措辞:

警告tstruct.c:1 typedef不能是静态的。静态关键字被忽略


我认为这更清楚但我现在有些疑惑:


这是真的吗?


我的理由是static关键字只能应用于

对象,而typedef不是对象。 (显然还有

另一个模糊的意思是静态。让我们暂时离开)


另一个问题是msvc和gcc说一些关于

多个存储类的信息。我无法理解。为什么?


另请注意,lcc-win仅发出警告。另外两个问题

错误和编译失败。这是一个如此糟糕的错误,

保证编译代码失败吗?

-

jacob navia

jacob at jacob point remcomp point fr

logiciels / informatique
http://www.cs.virginia.edu/~lcc-win32

解决方案



" jacob navia" < ja *** @ nospam.com写信息

news:g2 ********** @ aioe.org ...


考虑这段代码


static typedef struct {

int boo;

} FOO;


这与MSVC激起:

---------------------------- -

Microsoft(R)C / C ++优化编译器版本14.00.50727.762(适用于x64)


tstruct.c

tstruct.c(1):错误C2159:指定多个存储类


另一个问题是msvc和gcc都说了一些关于

多个存储类的信息。我无法理解。为什么?



我认为typedef本身被认为是存储类说明符(例如

static),用于语法。并且大概你只允许一个人在
时间:


static int * a [10]; / *使用静态存储声明变量a * /

typedef int * b [10]; / *声明类型别名b * /

-

Bartc


6月6日,8:09 am,jacob navia< ja ... @nospam.comwrote:


考虑此代码


static typedef struct {

int boo;


} FOO;


这与MSVC激起:

------------------------------

Microsoft(R)C / C ++优化编译器版本14.00 .50727.762 for x64

版权所有(C)Microsoft Corporation。保留所有权利。


tstruct.c

tstruct.c(1):错误C2159:指定多个存储类

------------------------------


有了gcc,我们有:

----------------------------

root @ ubuntu-vm:/ tmp #gcc tc

tc:1:错误:声明说明符中的多个存储类

------------------- ---------


凭借lcc-win我有

警告tstruct.c:声明中有多种类型。最后将使用

:''typedef''


with lcc-win64

-------- ----------------------

警告tstruct.c:1多次使用''typedef''

------------------------------


所有这些警告都具有误导性我的看法。我已经改变了

的措辞:

警告tstruct.c:1 typedef不能是静态的。静态关键字被忽略


我认为这更清楚但我现在有些疑惑:


这是真的吗?



这是真的吗?这些警告是误导性的?好吧,没有信息
或许是b $ b。你的警告更明确吗?好的,好的。那个typedef

不能是静态的吗?是的。


我的理由是static关键字只能应用于

对象,而typedef不是对象。 (显然还有

另一个模糊的意思是静态。让我们暂时离开)


另一个问题是msvc和gcc说一些关于

多个存储类的信息。我无法理解。为什么?



我不是编译器编写者,但我猜它只是

编译器解析代码的方式。 " typedef的"不是存储类(我不是/ b $ b想想< duck>),但它肯定不是一种类型,这就是

会否则在静态之后需要。我已经看到很多

编译器错误和警告_far_比这更加模糊。


请注意lcc-win只是问​​题一个警告。另外两个问题

错误和编译失败。这是一个如此糟糕的错误,

是否保证编译代码失败?



除非作为扩展,否则你将该构造记录为有用的东西

,我认为没有理由允许代码编译。它几乎没有什么意义,因为它没有意义,至少在其他几个主流编译器上没有编译,并且只是修复了一个硬错误似乎

适合我。


-


Cris


6月6日上午8:44,crisgoo ... @ telus.net写道:


6月6日上午8:09,jacob navia< ja ... @nospam.comwrote:


考虑此代码


static typedef struct {

int boo;


} FOO;


这与MSVC激起:

----------------- -------------

Microsoft(R)C / C ++优化编译器版本14.00.50727.762(适用于x64)


tstruct.c

tstruct.c(1):错误C2159:指定了多个存储类

------------------------------


使用gcc,我们有:

----------------------------

root @ ubuntu-vm:/ tmp #gcc tc

tc:1:错误:声明说明符中的多个存储类

------- ---------------------


有了lcc-win,我有

警告tstruct.c:声明中有多种类型。最后将使用

:''typedef''


with lcc-win64

------------------------------

警告tstruct.c:1多次使用''typedef ''

------------------------------



< snip>


另一个问题是msvc和gcc都说了一些关于

多个存储类我无法理解。为什么?



我不是编译器编写者,但我猜它只是

编译器解析代码的方式。 " typedef的"不是存储类(我不是/ b $ b想想< duck>),



< snip>


哎呀,发布后三十秒,我查了一下,然后瞧瞧
,typedef _is_存储类说明符...


叹息。


-


Cris


Consider this code

static typedef struct {
int boo;
} FOO;

This provokes with MSVC:
------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tstruct.c
tstruct.c(1) : error C2159: more than one storage class specified
------------------------------

With gcc we have:
----------------------------
root@ubuntu-vm:/tmp# gcc t.c
t.c:1: error: multiple storage classes in declaration specifiers
----------------------------

With lcc-win I had
Warning tstruct.c: 1 multiple types in a declaration. Last will be
used: ''typedef''

with lcc-win64
------------------------------
Warning tstruct.c: 1 multiple use of ''typedef''
------------------------------

All those warnings are misleading in my opinion. I have changed the
wording to:
Warning tstruct.c: 1 typedefs can''t be static. Static keyword ignored

I think that this is much more clear but I have now some doubts:

Is this true?

My reasoning is that the static keyword can only apply to an
object, and a typedef is not an object. (Obviously there is
another obscure meaning to "static". Let''s leave that for now)

Another problem is that both msvc and gcc say something about
"multiple storage classes" that I can''t understand. Why that?

Note too that lcc-win issues just a warning. The other two issue
an error and compilation fails. Is this such a bad error that
warrants a failure to compiler the code?
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32

解决方案


"jacob navia" <ja***@nospam.comwrote in message
news:g2**********@aioe.org...

Consider this code

static typedef struct {
int boo;
} FOO;

This provokes with MSVC:
------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tstruct.c
tstruct.c(1) : error C2159: more than one storage class specified

Another problem is that both msvc and gcc say something about
"multiple storage classes" that I can''t understand. Why that?

I think that typedef is itself considered a storage class specifier (like
static), for purposes of syntax. And presumably you''re only allowed one at a
time:

static int *a[10]; /* declares a variable a with static storage */
typedef int *b[10]; /* declares a type alias b */
--
Bartc


On Jun 6, 8:09 am, jacob navia <ja...@nospam.comwrote:

Consider this code

static typedef struct {
int boo;

} FOO;

This provokes with MSVC:
------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tstruct.c
tstruct.c(1) : error C2159: more than one storage class specified
------------------------------

With gcc we have:
----------------------------
root@ubuntu-vm:/tmp# gcc t.c
t.c:1: error: multiple storage classes in declaration specifiers
----------------------------

With lcc-win I had
Warning tstruct.c: 1 multiple types in a declaration. Last will be
used: ''typedef''

with lcc-win64
------------------------------
Warning tstruct.c: 1 multiple use of ''typedef''
------------------------------

All those warnings are misleading in my opinion. I have changed the
wording to:
Warning tstruct.c: 1 typedefs can''t be static. Static keyword ignored

I think that this is much more clear but I have now some doubts:

Is this true?

Is what true? That the warnings are misleading? Well, "uninformative"
perhaps. That your warning is more explicit? Sure, okay. That typedefs
can''t be static? Yes.

My reasoning is that the static keyword can only apply to an
object, and a typedef is not an object. (Obviously there is
another obscure meaning to "static". Let''s leave that for now)

Another problem is that both msvc and gcc say something about
"multiple storage classes" that I can''t understand. Why that?

I''m no compiler writer, but I''m guessing it''s just the way the
compiler parses the code. "typedef" isn''t a storage class (I don''t
think <duck>), but it''s certainly not a type either, which is what
would otherwise be required after that "static". I''ve seen many
compiler errors and warnings that are _far_ more obscure than this.

Note too that lcc-win issues just a warning. The other two issue
an error and compilation fails. Is this such a bad error that
warrants a failure to compiler the code?

Unless, as an extension, you document that construct to mean something
useful, I see no reason to allow the code to compile. It''s almost
meaningless as it stands, won''t compile on at least a couple of other
mainstream compilers, and is so simply fixed that a hard error seems
appropriate to me.

--

Cris


On Jun 6, 8:44 am, crisgoo...@telus.net wrote:

On Jun 6, 8:09 am, jacob navia <ja...@nospam.comwrote:

Consider this code

static typedef struct {
int boo;

} FOO;

This provokes with MSVC:
------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tstruct.c
tstruct.c(1) : error C2159: more than one storage class specified
------------------------------

With gcc we have:
----------------------------
root@ubuntu-vm:/tmp# gcc t.c
t.c:1: error: multiple storage classes in declaration specifiers
----------------------------

With lcc-win I had
Warning tstruct.c: 1 multiple types in a declaration. Last will be
used: ''typedef''

with lcc-win64
------------------------------
Warning tstruct.c: 1 multiple use of ''typedef''
------------------------------

<snip>

Another problem is that both msvc and gcc say something about
"multiple storage classes" that I can''t understand. Why that?


I''m no compiler writer, but I''m guessing it''s just the way the
compiler parses the code. "typedef" isn''t a storage class (I don''t
think <duck>),

<snip>

Oops, and thirty seconds after posting, I look it up, and lo and
behold, "typedef" _is_ a storage class specifier ...

Sigh.

--

Cris


这篇关于什么是正确的警告/错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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