编译时间与运行时间? [英] Compile time vs runtime?

查看:104
本文介绍了编译时间与运行时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读过,使用模板可以在编译时知道类型,并且使用继承来确定
类型首先在运行时决定。使用

指针和强制转换也表明这些类型将首先在

运行时知道。


但是有一些定义运行时代码的严格定义和一般可以使用的
编译时间代码?

I have read that using templates makes types know at compile time and
using inheritance the types are first decided at runtime. The use of
pointers and casts also indicates that the types will first be know at
runtime.

But is there some strict definitions that defines runtime code and
compile time code that can be used in general?

推荐答案

On 9 Maj, 11:28,桌面< f ... @ sss.comwrote:
On 9 Maj, 11:28, desktop <f...@sss.comwrote:

我读过使用模板可以在编译时知道类型和

使用继承类型首先在运行时决定。使用

指针和强制转换也表明这些类型将首先在

运行时知道。
I have read that using templates makes types know at compile time and
using inheritance the types are first decided at runtime. The use of
pointers and casts also indicates that the types will first be know at
runtime.



不知道这是否能回答你的问题;

模板背后的想法,你在编译时知道所有类型可以使用
,然后为每种类型生成代码。这就是为什么它被称为模板的原因,因为它不是你编写的代码被执行

,因为它只是一个模板使用由编译器生成将要执行的代码


Don''t know if this answers your question or not; the idea behind
templates it that you at compile-time knows all the types that can be
used, and then generate code for each of those types. That''s why it''s
called templates, since it''s not the code you write that gets executed
since it''s just a template used by the compiler to generate the code
that will be executed.


但是有一些严格的定义来定义运行时代码并且

一般可以使用的编译时间代码?
But is there some strict definitions that defines runtime code and
compile time code that can be used in general?



编译时是编译时,这意味着在编译应用程序之前,所有的魔法都会发生在
,这与类型安全有关因为你可以获得
。在运行时,魔法会在需要时发生,并且在编译时没有完全检查。这意味着对于编译时

多态性,你需要在编译时知道关于类型

的大部分内容,这就是为什么你不能拥有容器可以是

用于任何类型的编译代码,但必须分发源

(参见标准容器)。


-

Erik Wikstr?m

Compile-time is compile-time, meaning that all the magic takes place
before the application is compiled, which is about as typesafe as you
can get. With runtime the magic happens when needed and have not been
fully checked at compilation. This means that for compile-time
polymorphism you need to know most if not everything about the types
at compile-time, which is why you can''t have containers that can be
used with any type as compiled code, but have to distribute the source
(see the standard containers).

--
Erik Wikstr?m


Erik Wikstr?m写道:
Erik Wikstr?m wrote:

On 9 Maj,11:28,桌面< f ... @ sss.comwrote:
On 9 Maj, 11:28, desktop <f...@sss.comwrote:

>我已阅读使用模板在编译时使类型知道,并且使用继承,类型首先在运行时决定。
指针和强制转换的使用也表明这些类型将首先在运行时知道。
>I have read that using templates makes types know at compile time and
using inheritance the types are first decided at runtime. The use of
pointers and casts also indicates that the types will first be know at
runtime.



不知道这是否能回答你的问题;

模板背后的想法,你在编译时知道所有类型可以使用
,然后为每种类型生成代码。这就是为什么它被称为模板的原因,因为它不是你编写的代码被执行

,因为它只是一个模板使用由编译器生成将要执行的代码



Don''t know if this answers your question or not; the idea behind
templates it that you at compile-time knows all the types that can be
used, and then generate code for each of those types. That''s why it''s
called templates, since it''s not the code you write that gets executed
since it''s just a template used by the compiler to generate the code
that will be executed.


>但是是否有一些严格的定义来定义运行时代码和
编译时可以使用的代码一般吗?
>But is there some strict definitions that defines runtime code and
compile time code that can be used in general?



编译时是编译时,这意味着在编译应用程序之前所有的魔法都会发生在
,这就像类型安全一样因为你可以获得
。在运行时,魔法会在需要时发生,并且在编译时没有完全检查。这意味着对于编译时

多态性,你需要在编译时知道关于类型

的大部分内容,这就是为什么你不能拥有容器可以是

用于任何类型的编译代码,但必须分发源

(参见标准容器)。


Compile-time is compile-time, meaning that all the magic takes place
before the application is compiled, which is about as typesafe as you
can get. With runtime the magic happens when needed and have not been
fully checked at compilation. This means that for compile-time
polymorphism you need to know most if not everything about the types
at compile-time, which is why you can''t have containers that can be
used with any type as compiled code, but have to distribute the source
(see the standard containers).



编译时不可能有异构容器吗?我已经阅读了一个使用堆的方法,并确保容器中的每个

元素都已分配:

http://gethelp.devx.com/techtips/cpp.../10min0900 .asp


另一种技术涉及模拟动态多态(从基类派生
类)和奇怪的重复模板 br />
模式:CRTP:

http://en.wikipedia.org/wiki/Curious...mplate_Pattern


这些方法中的任何一个都无法帮我生成一个容器
在编译时
不同类型?


Is not possible to have a heterogeneous container at compile-time? I
have read about a method that uses the heap and makes sure that each
element in the container is allocated:

http://gethelp.devx.com/techtips/cpp.../10min0900.asp

Another technique deals with simulating dynamic polymorphism (deriving
classes from a base class) with the "The Curiously Recurring Template
Pattern": CRTP:

http://en.wikipedia.org/wiki/Curious...mplate_Pattern

Would either of these method not help me to generate a container with
different types at compile-time?


在9 Maj,13:57,桌面< f ... @ sss.comwrote:
On 9 Maj, 13:57, desktop <f...@sss.comwrote:

Erik Wikstr?m写道:
Erik Wikstr?m wrote:

On 9 Maj,11:28,桌面< f ... @ sss.comwrote:
On 9 Maj, 11:28, desktop <f...@sss.comwrote:

我读过使用模板制作在编译时知道类型和

使用继承类型首先在运行时决定。使用

指针和强制转换也表明这些类型将首先在

运行时知道。
I have read that using templates makes types know at compile time and
using inheritance the types are first decided at runtime. The use of
pointers and casts also indicates that the types will first be know at
runtime.


不知道这是否能回答你的问题;

模板背后的想法,你在编译时知道所有类型可以使用
,然后为每种类型生成代码。这就是为什么它被称为模板的原因,因为它不是你编写的代码被执行

,因为它只是一个模板使用由编译器生成将要执行的代码


Don''t know if this answers your question or not; the idea behind
templates it that you at compile-time knows all the types that can be
used, and then generate code for each of those types. That''s why it''s
called templates, since it''s not the code you write that gets executed
since it''s just a template used by the compiler to generate the code
that will be executed.


但是有一些严格的定义来定义运行时代码和

编译时代码一般可以用吗?
But is there some strict definitions that defines runtime code and
compile time code that can be used in general?


编译时是编译时,意味着在应用程序之前发生了所有魔法

编译,这是类似于你可以得到的b / b类型安全。在运行时,魔法会在需要时发生,并且在编译时没有完全检查。这意味着对于编译时

多态性,你需要在编译时知道关于类型

的大部分内容,这就是为什么你不能拥有容器可以是

用于任何类型的编译代码,但必须分发源

(参见标准容器)。
Compile-time is compile-time, meaning that all the magic takes place
before the application is compiled, which is about as typesafe as you
can get. With runtime the magic happens when needed and have not been
fully checked at compilation. This means that for compile-time
polymorphism you need to know most if not everything about the types
at compile-time, which is why you can''t have containers that can be
used with any type as compiled code, but have to distribute the source
(see the standard containers).



编译时不可能有异构容器吗?我已经阅读了一个使用堆的方法,并确保容器中的每个

元素都已分配:

http://gethelp.devx.com/techtips/cpp.../10min0900 .asp



在本文中,它们存储指向基类的指针,因此存储的元素

都是相同的类型。但是,当你取消引用它们时,你可以利用运行时多态性。

In this article they store pointers to a base-class, so the elements
stored are all of the same type. However when you dereference them you
can utilize runtime polymorphism.


另一种技术处理模拟动态多态(导出
$ b来自基类的$ b类)带有奇怪的重复模板

模式:CRTP:

http://en.wikipedia.org/wiki/Curious...mplate_Pattern


这两种方法中的任何一种都无法帮助我在编译时生成一个具有

不同类型的容器吗?
Another technique deals with simulating dynamic polymorphism (deriving
classes from a base class) with the "The Curiously Recurring Template
Pattern": CRTP:

http://en.wikipedia.org/wiki/Curious...mplate_Pattern

Would either of these method not help me to generate a container with
different types at compile-time?



否,请阅读常见问题解答中的此条目,了解如何使用模板创建

异构容器,注意第一种方法

与您发布的第一篇文章相同。
http://www.parashift.com/c++-faq-lit....html#faq-34.4


-

Erik Wikstr?m

No, read this entry in the FAQ for a description about how to create
heterogeneous container using templates, notice that the first method
is the same as in the first article you posted.
http://www.parashift.com/c++-faq-lit....html#faq-34.4

--
Erik Wikstr?m


这篇关于编译时间与运行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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