强/弱打字和指针 [英] strong/weak typing and pointers

查看:52
本文介绍了强/弱打字和指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



说强/弱打字没有区别是否正确如果一个人不使用任何指针(或地址操作员),那么
? br />

更具体地说,我特别想到Python与C ++。

所以,有没有任何例子(没有指针,引用或地址),

在Python和C ++中有不同的结果?


我会很感激所有的见解或对文学的指示。


TIA,

gabriel。


-

/ ------------ -------------------------------------------------- ----------- \

|我们的行为就像舒适和奢华一样|

|是生活的主要要求,|

|什么,我们需要让我们开心|

|是热情的东西。 (爱因斯坦)|

+ ------------------------------------- ------------------------------------ +

| za**@cs.uni-bonn.de __ @ /'' www.gabrielzachmann.org |

\ -------------- -------------------------------------------------- --------- /

解决方案

>如果一个人没有使用任何指针(或地址操作员),强/弱打字没有区别是

这是正确的吗?


看起来你错误的强/弱打字与静态/动态打字 -

完全不同的野兽。


Python实际上是强类型的 - 与php或perl相反,甚至是C,

这不起作用:


a =" 1" ; + 2


为1是一个字符串,2是一个整数。即使C是静态输入的,

也不会抱怨 - 你最终会得到一个意想不到的结果。


指针并不是邪恶的他们自己 - 这是创建

递归结构的必要条件。但故意施放指针可能非常有害

- 这是因为它禁止使用java和AFAIK等语言。

更具体地说,我特别想到Python与C ++。
那么,是否有任何示例(没有指针,引用或
地址),在Python和C ++中会产生不同的结果?




我很难理解你想要的东西。请详细说明。


-

问候,


Diez B. Roggisch


Gabriel Zachmann< za ** @ cs.uni-bonn.de>写道:

如果没有使用任何指针(或地址操作员),强/弱打字没有区别是否正确?


你会发现在这里没有达成共识的意思是强弱/弱

打字。在Python中,没有办法重新解释值

的位,就像它们是不同的类型一样。例如,像这样的代码在Python中不可能是



float x = 2.5;

printf("%d \ n",*(int *)& x);

更具体地说,我特别想到Python与C ++。
那么,有没有例子(没有指针,引用)或者说地址),这会在Python和C ++中产生不同的结果吗?




如果我理解你的问题,我相信不会;因为Python不会为b $ b提供必要的低级操作符。


2004年10月28日星期四18: 34:12 +0200,Diez B. Roggisch

< de ********* @ web.de>写道:

如果没有使用任何指针(或者说没有使用任何指针),强/弱打字没有区别是否正确?地址操作员??



你似乎错误地用强/弱打字进行静态/动态打字 - 一个完全不同的野兽。

Python实际上是强类型的 - 与php或perl甚至C相对,
这不起作用:

a =" 1" + 2

as1是一个字符串,2是一个整数。即使C是静态类型的,它也不会抱怨 - 你最终会得到意想不到的结果。




你没提到C ++。试试这个...


std :: string s =" Wow";

s + = 3.141592654; //完全有效

s = 3.141592654; //也有效


Andrea



Is it correct to say that strong/weak typing does not make a difference
if one does not use any pointers (or adress-taking operator)?

More concretely, I am thinking particularly of Python vs C++.
So, are there any examples (without pointers, references, or adress-taking),
which would have a different result in Python and in C++?

I would appreciate all insights or pointers to literature.

TIA,
gabriel.

--
/-------------------------------------------------------------------------\
| We act as though comfort and luxury |
| were the chief requirements of life, |
| when all that we need to make us happy |
| is something to be enthusiastic about. (Einstein) |
+-------------------------------------------------------------------------+
| za**@cs.uni-bonn.de __@/'' www.gabrielzachmann.org |
\-------------------------------------------------------------------------/

解决方案

> Is it correct to say that strong/weak typing does not make a difference

if one does not use any pointers (or adress-taking operator)?
It seems that you mistake strong/weak typing with static/dynamic typing - a
completely different beast.

Python is in fact strong typed - in opposition to php or perl or even C,
this won''t work:

a = "1" + 2

as "1" is a string and 2 an integer. And even though C is statically typed,
it won''t complain - you just end up with an unexpected result.

And pointers are not evil in themselves - the are a neccessity to create
recursive structures. But deliberately casting pointers can be very harmful
- a reason why its forbidden in languages like java and AFAIK ada.
More concretely, I am thinking particularly of Python vs C++.
So, are there any examples (without pointers, references, or
adress-taking), which would have a different result in Python and in C++?



I have difficulties to understand what you want here. Please elaborate.

--
Regards,

Diez B. Roggisch


Gabriel Zachmann <za**@cs.uni-bonn.de> wrote:

Is it correct to say that strong/weak typing does not make a difference
if one does not use any pointers (or adress-taking operator)?
You''ll find a lack of consensus here on what''s meant by "strong/weak
typing". In Python there''s no way to re-interpret the bits of a value
as if they were a different type. For example, code like this is
impossible in Python:

float x = 2.5;
printf("%d\n", *(int*)&x);
More concretely, I am thinking particularly of Python vs C++.
So, are there any examples (without pointers, references, or adress-taking),
which would have a different result in Python and in C++?



If I understand your question, I believe not; because Python doesn''t
provide the low-level operators that would be necessary for it.


On Thu, 28 Oct 2004 18:34:12 +0200, "Diez B. Roggisch"
<de*********@web.de> wrote:

Is it correct to say that strong/weak typing does not make a difference
if one does not use any pointers (or adress-taking operator)?



It seems that you mistake strong/weak typing with static/dynamic typing - a
completely different beast.

Python is in fact strong typed - in opposition to php or perl or even C,
this won''t work:

a = "1" + 2

as "1" is a string and 2 an integer. And even though C is statically typed,
it won''t complain - you just end up with an unexpected result.



You didn''t mention C++. Try this ...

std::string s = "Wow";
s += 3.141592654; // Perfectly valid
s = 3.141592654; // Also valid

Andrea


这篇关于强/弱打字和指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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