POINTER_MAX和POINTER_MIN ?? [英] POINTER_MAX and POINTER_MIN??

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

问题描述

有没有办法确定指针

可以容纳的最大值和最小值?

解决方案

< blockquote> coder写道:


有没有办法确定指针

可以容纳的最大值和最小值?



鉴于您在分配指针值时知道它们是什么,

您只需要随时跟踪它们(这意味着你会在他们被分配时知道他们是什么)。


你试图解决什么实际问题?因为我从未遇到过问题,所以我会描述你的方式,所以也许我对你的问题的理解是有缺陷的。


-

Chris" electric hedgehog" Dollin

我不明白这是...... Trevor Chaplin,/ Beiderbeck事件/


coder写道:


有没有办法确定指针

可以容纳的最大值和最小值?



这个问题要么是形象不对,要么是有意义的;我是

不确定是哪一个。


如果我们说的是J。随机指针,问题

毫无意义。 C没有定义

指针的全局排序,因此像maximum这样的术语和最小没有

的意思。试图宣称一个指针大于

另一个就像试图说酸味大于甜味。


然而,C *确实*定义了一个指向

指向单个对象或单个对象数组或

单个已分配内存区域的指针。以数组为例,

a指向[0]元素的指针是最小值,并且指向一个超过最终元素的指针(神话[N])
从[0]到[N-1]的数组的
元素是

最大值。类似地,在结构中,指向第一个

元素的指针是最小值,最大值是指向

的指针next在一个(可能是神话般的)数组中的相同结构。


即使在第二种情况下,问题还是一件小事

奇怪。指向或刚刚超过数组的指针有一个有效的

范围,从最小数组+ 0运行到最大数组+ N,

但是相同的指针变量可以被指向其他,

完全不同于阵列内部的地方。它甚至可以将
设置为NULL并且根本不指向任何内容。所以

有效范围是一种局部和暂时现象,

a指针指向的属性,而不是

指针本身。


-

Eric Sosman
es ***** @ acm- dot-org.inva lid


3月19日12:13,编码器 < plcoderREMOVET ... @ gmail.comwrote:


有没有办法确定指针

可以容纳的最大值和最小值?



我不确定你想要发现或实现的目标。


如果你想指点是类似于整数,你

假设一个平坦的地址空间。这不是

视图的有用点。


虽然在某些情况下(即公共对象内的地址),

支持指针排序,一般最大值
和最小值的概念充其量只是特定于实现。

Is there a way to determine the maximum and minimum values a pointer
can hold?

解决方案

coder wrote:

Is there a way to determine the maximum and minimum values a pointer
can hold?

Given that you know what they are when the pointer value is assigned,
you just have to keep track of them as you go along (which means you''ll
be able to know what they are when they''re assigned).

What actual problem are you trying to solve? Because I''ve never had a
problem I''d describe the way you did, so perhaps my understanding of
your problem is flawed.

--
Chris "electric hedgehog" Dollin
"What I don''t understand is this ..." Trevor Chaplin, /The Beiderbeck Affair/


coder wrote:

Is there a way to determine the maximum and minimum values a pointer
can hold?

The question is either ill-formed or meaningful; I''m
not sure which.

If we''re speaking of "J. Random Pointer," the question
makes no sense. C does not define a global ordering for
pointers, so terms like "maximum" and "minimum" have no
meaning. Trying to declare that one pointer is larger than
another is like trying to say that sour is larger than sweet.

However, C *does* define an ordering for pointers that
refer to a single object or a single array of objects or a
single allocated memory area. Taking an array, for example,
a pointer to the [0] element is the minimum value, and a
pointer to one past the final element (the mythical [N]
element of an array that goes from [0] to [N-1]) is the
maximum. Similarly, in a struct a pointer to the first
element is the minimum, and the maximum is a pointer to
the "next" identical struct in a (possibly mythical) array.

Even in the second case, though, the question is a trifle
strange. A pointer into or just past an array has a valid
range running from a minimum of array+0 to a maximum of array+N,
but that same pointer variable can be made to point to other,
completely different places that are not inside the array. It
can even be set to NULL and point to nothing at all. So the
"valid range" is something of a local and transitory phenomenon,
a property of what the pointer is pointing at and not of the
pointer itself.

--
Eric Sosman
es*****@acm-dot-org.invalid


On 19 Mar, 12:13, "coder" <plcoderREMOVET...@gmail.comwrote:

Is there a way to determine the maximum and minimum values a pointer
can hold?

I''m not sure what you are trying to discover or achieve.

If you are thinking of pointers as a being analogous to integers, you
are assuming a flat address space. This is not a helpful point of
view.

While, in certain contexts (i.e. addresses within a common "object"),
an ordering of pointers is supported, the idea of a general maximum
and minimum value is at best implementation-specific.


这篇关于POINTER_MAX和POINTER_MIN ??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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