从带有扩展的C到标准C的转换 [英] Translating from C with extensions to standard C

查看:60
本文介绍了从带有扩展的C到标准C的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几个编译器接受C语言的各种

扩展并生成本机

代码。但我想知道是否有任何提供

选项从C转换为一些扩展

到标准C.

解决方案



Spiros Bousbouras写道:


有几个编译器接受各种

扩展到C语言并生成本机

代码。但我想知道是否有任何提供

选项从C转换为一些扩展

到标准C.



恐怕不行。他们扩展C的原因主要是标准C

不能做他们想要的事情。标准C的目标是便携性

而扩展C旨在优化低级操作或

某些架构。

也许很少有扩展可以译文,但大部分都没有。


Cong Wang写道:


Spiros Bousbouras写道:


有几个编译器接受C语言的各种

扩展并生成本机

代码。但我想知道是否有任何提供

选项从C转换为一些扩展

到标准C.



恐怕不行。他们扩展C的原因主要是标准C

不能做他们想要的事情。标准C的目标是便携性

而扩展C旨在优化低级操作或

某些架构。

也许很少有扩展可以被翻译,但绝大多数没有。



你能给我一个扩展的例子吗?

无法翻译成(高效)标准C?




Spiros Bousbouras写道:


Cong Wang写道:
< blockquote class =post_quotes>
Spiros Bousbouras写道:


有几个编译器接受各种

扩展到C语言并生成本地

代码。但我想知道是否有任何提供

选项从C转换为一些扩展

到标准C.



恐怕不行。他们扩展C的原因主要是标准C

不能做他们想要的事情。标准C的目标是便携性

而扩展C旨在优化低级操作或

某些架构。

也许很少有扩展可以被翻译,但绝大多数没有。



你能给我一个扩展的例子吗?

无法翻译成(高效)标准C?



当然。以下代码来自Linux内核,用

GCC扩展编写:


#define typecheck(type,x)\

({type __dummy; \

typeof(x)__dummy2; \

(void)(& __ dummy ==& __ dummy2); \

1; \

})


很难将其翻译成标准C.

当然,GCC的另一个明显的扩展是无法翻译的内联

asm。


There are several compilers which accept various
extensions to the C language and produce native
code. But I wonder if there are any which offer the
option to translate from C with some extensions
to standard C.

解决方案


Spiros Bousbouras wrote:

There are several compilers which accept various
extensions to the C language and produce native
code. But I wonder if there are any which offer the
option to translate from C with some extensions
to standard C.

I am afraid not. The reason why they extend C is mainly that standard C
can''t do the things that they want. Standard C is aimed at portability
while extended C is aimed at optimizing for low level operations or for
certain architecture.
Maybe few extensions can be translated, but most not.


Cong Wang wrote:

Spiros Bousbouras wrote:

There are several compilers which accept various
extensions to the C language and produce native
code. But I wonder if there are any which offer the
option to translate from C with some extensions
to standard C.


I am afraid not. The reason why they extend C is mainly that standard C
can''t do the things that they want. Standard C is aimed at portability
while extended C is aimed at optimizing for low level operations or for
certain architecture.
Maybe few extensions can be translated, but most not.

Can you give me an example of an extension which
cannot be translated into (efficient) standard C ?



Spiros Bousbouras wrote:

Cong Wang wrote:

Spiros Bousbouras wrote:

There are several compilers which accept various
extensions to the C language and produce native
code. But I wonder if there are any which offer the
option to translate from C with some extensions
to standard C.

I am afraid not. The reason why they extend C is mainly that standard C
can''t do the things that they want. Standard C is aimed at portability
while extended C is aimed at optimizing for low level operations or for
certain architecture.
Maybe few extensions can be translated, but most not.


Can you give me an example of an extension which
cannot be translated into (efficient) standard C ?

Of course. The following code is from Linux kernel and is written with
GCC extensions:

#define typecheck(type,x) \
({ type __dummy; \
typeof(x) __dummy2; \
(void)(&__dummy == &__dummy2); \
1; \
})

It can hardly be translated into standard C.
And another obvious extension of GCC that can''t be translated is inline
asm, of course.


这篇关于从带有扩展的C到标准C的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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