- 论坛徽章:
- 2
|
关于pointer与integer
野路子,关于标准什么的,你也不屑。哦,是不拘泥。所以我也懒得多提。
但在你发散你的思维前,在将问题提升到哲学高度前,能沉下心来先看看《K&R》或者《C A reference manual》这些书,而不是凭自己的经验与臆想吗?
你在china-pub上买了上万元的书就只是收藏用?
这些忠告,你又听得进去吗?
sacry 发表于 2012-04-28 00:52
同样学C,A往哲学上学,B往标准学,C往实际开发学,都没有问题,
但是让讨论一个具体问题的时候,别不把计算机科学当科学,事实就在那里,瞎扯有意义么....
1. c faq
http://c-faq.com/ptrs/int2ptr.html
Once upon a time, it was guaranteed that a pointer could be converted to an integer (though one never knew whether an int or a long might be required),
...
The ANSI/ISO C Standard, in order to ensure that C is widely implementable, has weakened those earlier guarantees.
Pointer-to-integer and integer-to-pointer conversions are implementation-defined (see question 11.33),
and there is no longer any guarantee that pointers can be converted to integers and back, without change.
...
2. Rationale
Rationale for American National Standard for Information Systems - Programming Language - C
http://www.lysator.liu.se/c/rat/c3.html#3-3-4
Nothing portable can be said about casting integers to pointers, or vice versa, since the two are now incommensurate.
3. K&R
K&R A.6.6 Pointers and Integers
A pointer may be converted to an integral type large enough to hold it; the required size is implementation-dependent. The mapping function is also implementation-dependent.
4. C A reference manual
C A reference manual
6.2.3 conversions to integer type
...
C programmers used to assume that pointers could be converted to type long and back without loss of information.
Although this was almost always true, it is not required by the language definition.
In C99, the types intptr_t and uintptr_t, if defined in stdint.h, are signed and unsigned integer types capable of holding pointers.
The problem is that some computers may have pointer representation that are longer than the largest integer type.
|
|