topics

全部话题 - 话题: pointer
首页 6 7 8 9 10 (共10页)
c***g
发帖数: 472
1
来自主题: Programming版 - 一个简单的小问题
According to the language definition, an integral constant expression with t
he value 0 in a pointer context is converted into a null pointer at compil
e time.
As a matter of style, many programmers prefer not to have unadorned 0
's scattered through their programs, some representing numbers and some repr
esenting pointers. Therefore, the preprocessor macro NULL is defined (by sev
eral headers, including and ) as a null pointer constant
, typically 0 or ((void *)0)
Using NULL
m******t
发帖数: 4077
2
1,像pointer一样节约storage space。
2, 像pointer一样可以修改原来的变量
3,像pointer一样可以保持多态性
4,保证object存在,不会像pointer一样搞出nil来
我说的对不对?好有没有补充?
谢谢
h**o
发帖数: 548
3
来自主题: Programming版 - JHQ的一道指针题。
说的极是.
我想int *a[10]是10 个pointer, 每个pointer指向一个长度不定的array
int (*a)[10]是10 个pointer, 每个pointer指向一个int.
P*****f
发帖数: 2272
4
来自主题: Programming版 - JHQ的一道指针题。
int (*a)[10]是一个指针,指向一个 长度为10得int数组

说的极是.
我想int *a[10]是10 个pointer, 每个pointer指向一个长度不定的array
int (*a)[10]是10 个pointer, 每个pointer指向一个int.
t****t
发帖数: 6806
5
来自主题: Programming版 - 谁给详细说一下这句
Read the holy standard
section 4.3, 13.4, and 5.2.10, clause 6
I suspect you have some typo, or he has, because the type of function is
changed. Calling a function through a different type of function pointer is,
well, you guessed, undefined. If the conversion is (int(*)(int const&))
addValue, then it makes perfect sense.
6 A pointer to a function can be explicitly converted to a pointer to a
function of a different type. The effect of calling a function
through a pointer to
t****t
发帖数: 6806
6
来自主题: Programming版 - 一道面试题
0 cast to any pointer type returns null pointer. null pointer is null
pointer, it doesn't point to anything.
i***0
发帖数: 8469
7
how to do it ?=======Problem – coding in c++
I have two node pointer which may be in same link list or not.
The function should return me pointer where they are merging if they are
merging.
If the node pointers are not merging, it should return null pointer.
K*****n
发帖数: 65
8
来自主题: Programming版 - C++小插曲
I would not call it is a bug. It is an unfortunate reality we have to live
with.
Pointer is powerful and risky. Be cautious when you cast a pointer. Compiler
can not prevent abuse of pointer. For example, you
can get class private data by casting pointer.
Back to the original post, it is a bad programming practice to declare a
public virtual function in base class and to override it as private in
derived class. To make Compiler happy is just not enough. I give you
another example:
class A
{
..
O******e
发帖数: 734
9
来自主题: Programming版 - 问个c调用fortran函数的问题
A C pointer is just a simple address to a contiguous piece of memory, but
a Fortran pointer is actually a complicated internal data structure in
the Fortran run-time library, which stores not only the starting address
of the target, but also the rank, the lower and upper bounds and the
strides of the indices, and it may therefore point to a collection of
noncontiguous pieces of memory. For example, a Fortran pointer x can
point to a normal (5,5) array, and another Fortran pointer y can point to
mw
发帖数: 525
10
来自主题: Programming版 - is smart_ptr really that good?
hi,
Today the Tech Lead in the team told me that he want to re-write all the
bare pointers to smart ptr
for me this is kinda insane, taken into account that the extensive usage of
c++ pointers in our existing code.
my question is:
Is smart pointer really that good? we are working on an ultra-high intensity
TCPIP IO software, I cannot understand what's the benefit of smart pointer
here.
can any guru here share his/her opinion?
thanks a lot
f**y
发帖数: 138
11
来自主题: Programming版 - 关于数组
Here a and &a are both pointers and have the same value.
But a + 1 and &a + 1 are different. a is a simple pointer, &a is pointer of
pointer.
a + 1 points to the next element in the array.
&a + 1 points to the address after a, so &a + 1 == (void *)a + sizeof(a)
s******u
发帖数: 179
12
在fortran 90中,我将一个稀疏矩阵存成下面的数据格式:
TYPE:: rsm !Real sparse matrix
integer:: numbers !number of nonzero value in the matrix
integer,dimension(:),pointer::rows
integer,dimension(:),pointer::columns
real ,dimension(:),pointer::values
END TYPE rsm
然后用指针读取这个矩阵
TYPE:: rsmptr
type(rsm),pointer::p
END TYPE rsmptr
每次读取都是从第一个到后一个顺序读取。后面的程序中要对这个矩阵多次重复的读取(且是在内存中)
,这样的存法,读取的效率不怎么高。我也试过把一个矩阵中的元素存成一个node的数
据结构:
type:: node
integer :: rows
integer
t****t
发帖数: 6806
13
来自主题: Programming版 - 出个题考考大家:)
把fb去掉再来, cdecl不接受参数名, 比如说
cdecl> explain char foo(char)
declare foo as function (char) returning char
cdecl> explain char foo(char x)
syntax error
所以
cdecl> explain char *(*ff(char *(*)()))()
declare ff as function (pointer to function returning pointer to char)
returning pointer to function returning pointer to char
h****8
发帖数: 599
14
来自主题: Programming版 - 出个题考考大家:)
哪里错了 楼下都说了
declare ff as function (pointer to function returning pointer to char)
returning pointer to function returning pointer to char
X****r
发帖数: 3557
15
来自主题: Programming版 - c++ question
I think they are wrong, because what you said is called
function-to-pointer conversion:
4.3 Function-to-pointer conversion [conv.func]
1 An lvalue of function type T can be converted to an rvalue of type
"pointer to T." The result is a pointer to the function.
However, there is a footnote specifically saying:
* This conversion never applies to nonstatic member functions because
an lvalue that refers to a nonstatic member function cannot be ob-
tained.

as
d****p
发帖数: 685
16
来自主题: Programming版 - Interview question: is the following code OK?
boost::shared_ptr is a smart pointer which contains a shared_count object
that manages count ref on the raw pointer. So the static function returns a
valid pointer to a valid object (the Foo(id)).

will
copy of the same object too , both of which contais that pointer (but the
memory is no longer available).
statement is not valid.
g**e
发帖数: 6127
17
来自主题: Programming版 - find start point of loop from linked list
贴一个google到的,看上去应该是o(n)
Let x = the head of the list
Let y = some point on the loop (e.g. the place we detected the loop)
findloophead(x,y){
pointers t, a=x, b=next(y), c=y
while (1) {
t=midpoint (a,c)
if find (b,t,c) // t is in loop
then c=t
else a=next(t) // t is out of loop. move a to t
t= midpoint (b,c)
if find (a,t,c)
then c=t
else b=next(t)
if (a==b) return a;
if (a==c) or (b==c) return c;
}}
midpoint (e,f):
returns the pointer to the middle ... 阅读全帖
m****s
发帖数: 1481
18
谢谢,我刚才搜索了半天,看到stackoverflow有人问类似的问题,确实是应该用引用
。因为c++子函数传进来的变量是copy,所以进来的pointer是主函数那个pointer的
local copy,如果主函数没有初始化,子函数分配的内存并没有赋值给主函数的
pointer,一个解决办法是子函数用int **a,主函数把没有分配内存的pointer的地址
传进去,也就是call的时候用&a。另一个办法就是你说的用int * &a,pass by reference。
m*******e
发帖数: 20
19
来自主题: Programming版 - Questions about c code
(i) (MATHEAD *)(a)-1 means you explictely convert pointer "a" into a MATHEAD
type pointer("a" is very likely to be a void* pointer originally), and then
make the pointer point to the memory place immediately before the current
place it does.
(ii) Not very sure about your second question. Actually I think such macro
does not make any sense...Well hope somebody can give out a more precise
answer.
j******n
发帖数: 271
20
来自主题: Programming版 - 讨论 找单链表倒数m的节点 (转载)
What is the concern here? In each iteration, at most 4 pointers are
referenced: two pointers to the current and the two pointer to next elements
of them. Even if they are all in different pages, in each iteration we
reference at most 4 pages, which is 4*4KB and can fit in today's L1 cache.
Below is my solution without advancing each pointer twice. Please comment.
1: #include
2: #include
3: #include
4: using namespace std;
5:
6: template阅读全帖
c**********e
发帖数: 2007
21
来自主题: Programming版 - C++ Q90 - Q92 (转载)
【 以下文字转载自 JobHunting 讨论区 】
发信人: careerchange (Stupid), 信区: JobHunting
标 题: C++ Q90 - Q92
发信站: BBS 未名空间站 (Fri Oct 14 23:32:13 2011, 美东)
C++ Q90: class templates
What type of class template can be nested?
A. Only non-template classes
B. Only class templates
C. Both class templates and non-template classes
D. Neither class templates nor non-template classes
C++ Q91: this pointer
Which one of the following operations requires explicit use of a this
pointer?
A. Calling a member function that require... 阅读全帖
d****n
发帖数: 1637
22
来自主题: Programming版 - 最新某公司onsite面试题 (转载)
1. I cant make sure.
but its outputs this
2,5
2. googled
1. const char *p : means p is pointer pointing to a constant char i.e.
you can not change the content of the location where it is pointing but u
can change the pointer itself to point to some other char.
2. char const *p, and char * const p : both are same & in this case p
is a constant pointer poiting to some char location. you can change the
contents of that location but u can't change the pointer to point to some
other locati... 阅读全帖
t****t
发帖数: 6806
23
来自主题: Programming版 - 最新某公司onsite面试题 (转载)
a has type int[5]
&a has type (pointer to int[5])
&a+1 has type (pointer to int[5])
you assign (pointer to int[5]) to int* and you get an error in c++.
c++ is strong type language, while in c all types of pointer can be
implicitly converted.
s****s
发帖数: 50
24
来自主题: Programming版 - 最新某公司onsite面试题 (转载)
C++ Faq:
[18.5] What's the difference between "Fred const* p", "Fred* const p" and "F
red const* const p"?
You have to read pointer declarations right-to-left.
Fred const* p means "p points to a constant Fred": the Fred object can't be
changed via p.
Fred* const p means "p is a const pointer to a Fred": you can't change the p
ointer p, but you can change the Fred object via p.
Fred const* const p means "p is a constant pointer to a constant Fred": you
can't change the pointer p itself, nor can y... 阅读全帖
A*********l
发帖数: 2005
25
来自主题: Programming版 - C++方法全都内联有什么坏处?
If user's input is pure data, like string/xml kind of stuff, yes, you code
should handle all that and should never crash. Just like a server receiving
request from client, no matter what kind of garbage data client throws at
your server, your server should not crash.
But at in-process API level? How can you avoid crash if in language like C/C
++, someone simply pass you a garbage pointer? You can check whether if the
pointer is NULL to avoid crash, but you can't really check whether that
pointer... 阅读全帖
c*******y
发帖数: 1630
26
来自主题: Programming版 - C++ 菜鸟问一个关于template 的问题。
good, works for both
/usr/include/c++/4.6.3/bits/stl_iterator_base_types.h
/// Partial specialization for pointer types.
template
struct iterator_traits<_Tp*>
{
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef _Tp& reference;
};
/// Partial specialization fo... 阅读全帖
j******t
发帖数: 788
27
No, I guess we are not talking about the same thing.
RAII is all about the allocation/deallocation of resource. It is just one of
usages of smart pointer, which actually was shared_pointer when RAII
mechanism was born. But that is not the reason people invented smart
pointer, I guess you are confused with the two idioms, smart pointer is much
much more than either shared_pointer or autopointer. Let's just forget
about these two dead words. Do not assume they are the same as smart pointer
.

,
t***t
发帖数: 6066
28
来自主题: Programming版 - C++问题: 指针变量是哪里产生的?
for this case, no runtime check is needed.
compiler should give warning whenever an integer is used as address and
assigned to a pointer. which means, pointer can only be get from new or from
another pointer. IMO, developer should never do it.
so such code will always get warning and alert the developer.
or, can set the compiler stricter, give error instead of warning.
i don't see the need to assign integer to pointer unless for very low level
programming.

are
n****1
发帖数: 1136
29
Poor man, you do not have a single clue about the connection between opaque
pointer and opaque struct, do you?
Can you given give me a precise definition of opaque pointer? It is a
pointer to some struct, right? Why should people call it opaque pointer if
it does not point to a opaque struct?
N******K
发帖数: 10202
30
来自主题: Programming版 - 问个c++ struct和指针问题
struct pixel
{
double a // 8 byte
double b // 8 byte
}
auto pointer = new pixel[10]
pointer += 9
这个计算 是怎么实现的
是不是 逻辑上相当于 **pointer += 9*16
**pointer是指针的值 uint64类型 内存单元为byte
S*A
发帖数: 7142
31
来自主题: Programming版 - C一个问题搞不懂
Dereference means accessing the memory variable by the pointer
address. In other words, dereference meaning memory load or
store using pointer.
int multi[4][5];
multi【0】 as expression can decay to a pointer. That itself
is not an deference. Just like
int array[5];
expression "array" by itself is not a dereference.
It is just a pointer.
S*A
发帖数: 7142
32
It only verify the "from" pointer. Because the "from" is pass by
the user space program. It might be an invalid pointer, or pointer
haven't mmap to any memory.
The "to" pointer is not validated at all. It will assume the "to"
memory buffer is big enough. If not. It will corrupt memory (likely)
or generate kernel panic(unlikely).
S*A
发帖数: 7142
33
来自主题: Programming版 - 为啥允许这样的const设计

这不是冗余的规则,其实是你不允许出现左边 const 是冗余的规则。
是你自己为了自己(片面)的理解方便强加出来的规则。所以最后为了
补全还是给最左边 const 加个反规则的例外。
const 是个 modifier, 是可以放左边的。其实 C 编译的时候是
把 const 作用在当前 type 的。当 * 出现以后,当前 type 就是
pointer type。所以 const 作用到 pointer 上。
对,const 作用在 typedef pointer就是很好一个例子。
其实只要你真正理解了 C 的编译器是如何工作的,这些左边右边规则
是不需要记住的,你为了记这个不是规则的规则还要加个违反规则的特
例给最左边const。
你只需要知道 modifier 作用在当前 type 上面就可以了。
其他就是最自然的实现。
style guide 指的是 style。就是等价时候可以这样可以那样的一个取向。
但是 pointer const 这个在 * 左边右边就不是 style 了,是 correctness
的问题了。当然不是 style guide cover 的。所以我... 阅读全帖
g****t
发帖数: 31659
34
牛。GC你统计过longest pause什么的吗?
gc作者之一在这里
https://groups.google.com/forum/m/?fromgroups#!topic/golang-dev/Ab1sFeoZg_8


: 罪魁祸首找到了:obj := *(*uintptr)(unsafe.Pointer(b i))

: // scanobject scans the object starting at b, adding pointers to
gcw.

: // b must point to the beginning of a heap object or an oblet.

: // scanobject consults the GC bitmap for the pointer mask and
the

: // spans for the size of the object.

: //

: //go:nowritebarrier

: func scanobject(b uintptr, gc... 阅读全帖
g****t
发帖数: 31659
35
牛。GC你统计过longest pause什么的吗?
gc作者之一在这里
https://groups.google.com/forum/m/?fromgroups#!topic/golang-dev/Ab1sFeoZg_8


: 罪魁祸首找到了:obj := *(*uintptr)(unsafe.Pointer(b i))

: // scanobject scans the object starting at b, adding pointers to
gcw.

: // b must point to the beginning of a heap object or an oblet.

: // scanobject consults the GC bitmap for the pointer mask and
the

: // spans for the size of the object.

: //

: //go:nowritebarrier

: func scanobject(b uintptr, gc... 阅读全帖
t********e
发帖数: 1169
36
【 以下文字转载自 JobHunting 讨论区 】
发信人: mitbbs59 (bEQi), 信区: JobHunting
标 题: 本版1年以内的所有 面经题目,含帖子link [为大家方便]
发信站: BBS 未名空间站 (Fri Jan 29 14:20:44 2010, 美东)
不敢保证全部涵盖,大部分的都在。
我自己找了一遍,大家一起用着都方便。
不过只是含有题目的帖子 我才包含进来了,只分享经验没贴题目的 我都没有包含
进来。
大家复习着方便。
1. 一个sorted interger Array[1...N], 已知范围 1...N+1. 已知一个数字missing。
找该数字。
把原题改为unsorted,找missing数字。 performance。
2. 复制linked list。 已知每个节点有两个pointer,一个指向后一个节点,另一个指向
其他任意一节点。 O(n)时间内,无附加内存,复制该linked list。(存储不连续)
3. 一个party N个人,如果一个人不认识任何其他人,又被任何其他人认识,此人为
celeb... 阅读全帖
t********e
发帖数: 1169
37
【 以下文字转载自 JobHunting 讨论区 】
发信人: mitbbs59 (bEQi), 信区: JobHunting
标 题: 本版1年以内的所有 面经题目,含帖子link [为大家方便]
发信站: BBS 未名空间站 (Fri Jan 29 14:20:44 2010, 美东)
不敢保证全部涵盖,大部分的都在。
我自己找了一遍,大家一起用着都方便。
不过只是含有题目的帖子 我才包含进来了,只分享经验没贴题目的 我都没有包含
进来。
大家复习着方便。
1. 一个sorted interger Array[1...N], 已知范围 1...N+1. 已知一个数字missing。
找该数字。
把原题改为unsorted,找missing数字。 performance。
2. 复制linked list。 已知每个节点有两个pointer,一个指向后一个节点,另一个指向
其他任意一节点。 O(n)时间内,无附加内存,复制该linked list。(存储不连续)
3. 一个party N个人,如果一个人不认识任何其他人,又被任何其他人认识,此人为
celeb... 阅读全帖
K****n
发帖数: 5970
38
看,这就是google这个网站全部的源代码:
大哥大嫂过年好!
content="text/html; charset=UTF-8">Google