是“typedef int int;”非法???? [英] is "typedef int int;" illegal????

查看:60
本文介绍了是“typedef int int;”非法????的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




假设你有一个地方


#define BOOL int


和某个地方否则


typedef BOOL int;


这给了


typedef int int;


对我来说,这看起来像是一个空任务:


a = a;


它会破坏什么如果lcc-win32会接受,

可能带有警告?


编译器*是否需要*拒绝?

Microsoft MSVC:拒绝它。

lcc-win32现在拒绝它。

gcc(没有标志)接受它有一些警告。


谢谢


jacob

---

免费的Windows编译系统:
http://www.cs.virginia.edu/~lcc- win32

Hi

Suppose you have somewhere

#define BOOL int

and somewhere else

typedef BOOL int;

This gives

typedef int int;

To me, this looks like a null assignment:

a = a;

Would it break something if lcc-win32 would accept that,
maybe with a warning?

Is the compiler *required* to reject that?

Microsoft MSVC: rejects it.
lcc-win32 now rejects it.
gcc (with no flags) accepts it with some warnnings.

Thanks

jacob
---
A free compiler system for windows:
http://www.cs.virginia.edu/~lcc-win32

推荐答案

jacob navia写道:
jacob navia wrote:

假设y你有什么地方

#define BOOL int

和其他地方

typedef BOOL int;

这给了

typedef int int;


typedef名称必须是标识符,这里有一个关键字。

对我来说,这看起来像是一个空任务:

a = a;


也许从实施者的角度来看,但标准没有

允许它。

它会破坏什么如果lcc-win32会接受,
可能有警告?


需要诊断,之后你可以做任何你想要的事情,包括继续像往常一样编译程序

会。

编译器*要求*拒绝吗?


定义拒绝。您需要生成诊断,就是它。

Microsoft MSVC:拒绝它。


好​​。

lcc-win32现在拒绝它。


好​​。

gcc(没有标志)接受一些警告。
Hi

Suppose you have somewhere

#define BOOL int

and somewhere else

typedef BOOL int;

This gives

typedef int int;
The typedef name must be an identifier, here you have a keyword.
To me, this looks like a null assignment:

a = a;
Maybe from an implementor''s point of view but the Standard does not
allow it.
Would it break something if lcc-win32 would accept that,
maybe with a warning?
A diagnostic would be required, after that you can do anything you
want, including continuing to compile the program as you normally
would.
Is the compiler *required* to reject that?
Define reject. You are required to produce a diagnostic, that''s it.
Microsoft MSVC: rejects it.
Good.
lcc-win32 now rejects it.
Good.
gcc (with no flags) accepts it with some warnnings.




它无法为我编译(gcc 4.0.2):

错误:声明说明符中有两个或更多数据类型


Robert Gamble



It fails to compile for me (gcc 4.0.2):
error: two or more data types in declaration specifiers

Robert Gamble


Robert Gambleaécrit:
Robert Gamble a écrit :
jacob navia写道:
jacob navia wrote:


#define BOOL int

和其他地方

typedef BOOL int;

这个给出

typedef int int;

typedef名称必须是标识符,这里有关键字。

Hi

Suppose you have somewhere

#define BOOL int

and somewhere else

typedef BOOL int;

This gives

typedef int int;

The typedef name must be an identifier, here you have a keyword.

对我来说,这看起来像是一个空的任务:

a = a;
To me, this looks like a null assignment:

a = a;



也许从实施者的角度来看,但标准不是
允许它。


Maybe from an implementor''s point of view but the Standard does not
allow it.

如果lcc-win32会接受它会破坏某些东西,
可能与警告?
Would it break something if lcc-win32 would accept that,
maybe with a warning?



需要诊断,之后你可以做任何你想要的事情,包括继续像往常一样编译程序。


A diagnostic would be required, after that you can do anything you
want, including continuing to compile the program as you normally
would.




好​​的,这就是我的想法。



OK, that is what I had in mind.

编译器*是否需要*拒绝?

定义拒绝。您需要生成诊断,就是它。
Is the compiler *required* to reject that?

Define reject. You are required to produce a diagnostic, that''s it.




拒绝意味着程序无法编译。程序编译后,警告不是拒绝




Reject means the program fails to compile. A warning is not a reject
since the program compiles.

Microsoft MSVC:拒绝它。

很好。

Microsoft MSVC: rejects it.

Good.

lcc-win32现在拒绝它。
lcc-win32 now rejects it.



好​​。


Good.

gcc(没有标志)接受它有一些警告。
gcc (with no flags) accepts it with some warnnings.



它无法为我编译(gcc 4.0.2):
错误:声明中有两个或更多数据类型说明符


It fails to compile for me (gcc 4.0.2):
error: two or more data types in declaration specifiers




奇怪,我得到以下内容:


[root @ gateway root] #gcc -v

从/usr/lib/gcc-lib/i586-mandrake-linux-gnu/2.96/specs阅读规格

gcc版本2.96 20000731(Mandrake Linux 8.2 2.96-0.76mdk)

[root @ gateway root] #cat tint.c

typedef int int;

[root @ gateway root] #gcc -c tint.c

tint.c:1:警告:空声明中无用的关键字或类型名称

tint.c:1:警告:空声明

[根@ gatew ay root] #ls -l tint.o

-rw-r - r-- 1 root root 703 Mar 24 16:17 tint.o

[root @网关根>#


程序不被拒绝。

Robert Gamble



Strange, I get the following:

[root@gateway root]# gcc -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/2.96/specs
gcc version 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)
[root@gateway root]# cat tint.c
typedef int int;
[root@gateway root]# gcc -c tint.c
tint.c:1: warning: useless keyword or type name in empty declaration
tint.c:1: warning: empty declaration
[root@gateway root]# ls -l tint.o
-rw-r--r-- 1 root root 703 Mar 24 16:17 tint.o
[root@gateway root]#

Program is not rejected.
Robert Gamble



jacob navia写道:
jacob navia wrote:
Robert Gambleaécrit:
Robert Gamble a écrit :
jacob navia写道:
jacob navia wrote:


假设你有一个地方

#define BOOL int

和其他地方

typedef BOOL int;

这给了

typedef int int;
Hi

Suppose you have somewhere

#define BOOL int

and somewhere else

typedef BOOL int;

This gives

typedef int int;



typedef名称必须是标识符,这里有关键字。


The typedef name must be an identifier, here you have a keyword.

对我来说,这看起来像是一个空任务:

a = a;
To me, this looks like a null assignment:

a = a;



也许是从实现者的观点来看,但标准不允许它。


Maybe from an implementor''s point of view but the Standard does not
allow it.

如果lcc-win32接受,它会破坏什么,
可能有警告?
Would it break something if lcc-win32 would accept that,
maybe with a warning?



需要诊断,之后你可以做任何你想要的事情,包括继续像往常一样编译程序
会这样。


A diagnostic would be required, after that you can do anything you
want, including continuing to compile the program as you normally
would.



好的,这就是我的想法。



OK, that is what I had in mind.

编译器*是否需要*拒绝这个?
Is the compiler *required* to reject that?



定义拒绝。您需要生成诊断,就是它。


Define reject. You are required to produce a diagnostic, that''s it.



拒绝意味着程序无法编译。一个警告不是拒绝
因为程序编译。



Reject means the program fails to compile. A warning is not a reject
since the program compiles.




如果没有定义,你不需要拒绝这样的程序

但你肯定可以这样做。



With that definition no, you are not required to reject such a program
but you are certainly free to do so.

Microsoft MSVC:拒绝它。
Microsoft MSVC: rejects it.



好​​。


Good.

lcc-win32现在拒绝它。
lcc-win32 now rejects it.



好​​。


Good.

gcc(没有标志)接受一些警告。
gcc (with no flags) accepts it with some warnnings.



它无法为我编译(gcc 4.0.2):
错误:声明说明符中有两个或更多数据类型


It fails to compile for me (gcc 4.0.2):
error: two or more data types in declaration specifiers



奇怪,我得到以下内容:

[root @ gateway root] #gcc - v
从/usr/lib/gcc-lib/i586-mandrake-linux-gnu/2.96/specs阅读规范
gcc版本2.96 20000731(Mandrake Linux 8.2 2.96-0.76mdk)
[ root @ gateway root] #cat tint.c
typedef int int;
[root @ gateway root] #gcc -c tint.c
tint.c:1:警告:空声明中无用的关键字或类型名称
tint.c:1:警告:空声明
[root @ gateway root] #ls -l tint.o
-rw-r - r-- 1 root root 703 Mar 24 16:17 tint.o
[root @ gateway root]#

程序不会被拒绝。



Strange, I get the following:

[root@gateway root]# gcc -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/2.96/specs
gcc version 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)
[root@gateway root]# cat tint.c
typedef int int;
[root@gateway root]# gcc -c tint.c
tint.c:1: warning: useless keyword or type name in empty declaration
tint.c:1: warning: empty declaration
[root@gateway root]# ls -l tint.o
-rw-r--r-- 1 root root 703 Mar 24 16:17 tint.o
[root@gateway root]#

Program is not rejected.




自gcc 2.96以来有点变化,包括

的严格性语法和类型检查。请注意,诊断仍然是产生的b $ b。


Robert Gamble



Quite a bit has changed since gcc 2.96 including the strictness of the
syntax and type checking. Note though that a diagnostic was still
produced.

Robert Gamble


这篇关于是“typedef int int;”非法????的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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