由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教一个c的概念题
相关主题
amazon的那道题目c++ 程序一问
An example of strategy pattern问个面试题
one C++ question这个C++程序的运行结果是什么
请教C/C++小求教:这个程序为什么不能编译?
C++ Q42: (C22)c++疑难问题。。
C++: what is the output? How to interpret it?C: what is the output?
C++问题搞Compiler 有前途吗?
新手问个C++(Thinking in C++ source code)Interview questions, Bloomberg
相关话题的讨论汇总
话题: int话题: foo话题: 概念话题: while话题: pb
进入JobHunting版参与讨论
1 (共1页)
r******l
发帖数: 10760
1
void foo(int *p, int *q)
{
while (p ...
}
说其中的while永远进不去,因为p 远比q大12。这是为啥呢?什么地方有讲这种东西?有没有相关网页?多谢!
y***n
发帖数: 1594
2
这个是不是把p,q push 打function stack 上的地址,记不清楚了,看看fuction 的参
数是如何 push 到stack 上去的把。
r******l
发帖数: 10760
3
这种东西哪儿有呢?有没有相关的link?p和q为啥差12呢?这个跟编译器、OS、CPU结
构有关系么?还是永远是相差12?

【在 y***n 的大作中提到】
: 这个是不是把p,q push 打function stack 上的地址,记不清楚了,看看fuction 的参
: 数是如何 push 到stack 上去的把。

y***n
发帖数: 1594
d****n
发帖数: 12461
5
32bit gcc
不加o: p>q,差4 bytes
加o: p 你这个12很奇怪。

【在 r******l 的大作中提到】
: 这种东西哪儿有呢?有没有相关的link?p和q为啥差12呢?这个跟编译器、OS、CPU结
: 构有关系么?还是永远是相差12?

s**x
发帖数: 7506
6
Apparently the problem is in how you call that function.
r******l
发帖数: 10760
7
我是在VS里面单步跟进去看的。不过确实debug是p>q,release模式就是p p总是大于q的说法不对啊。
我还是去看看上面给的那个link吧。

【在 d****n 的大作中提到】
: 32bit gcc
: 不加o: p>q,差4 bytes
: 加o: p: 你这个12很奇怪。

d****n
发帖数: 12461
8
和如何call无关啊。function stack总是一个方向的。

【在 s**x 的大作中提到】
: Apparently the problem is in how you call that function.
c*******e
发帖数: 70
9
需要一点汇编语言的知识,在调用函数前,需要把形参压入栈中,每个函数开头的这段
汇编代码都相同,叫entry code。你可以查一下。

【在 r******l 的大作中提到】
: void foo(int *p, int *q)
: {
: while (p: ...
: }
: 说其中的while永远进不去,因为p: 远比q大12。这是为啥呢?什么地方有讲这种东西?有没有相关网页?多谢!

z******g
发帖数: 271
10
参见cdecl
相关主题
C++: what is the output? How to interpret it?c++ 程序一问
C++问题问个面试题
新手问个C++(Thinking in C++ source code)这个C++程序的运行结果是什么
进入JobHunting版参与讨论
c**y
发帖数: 172
11
写了个程序测了一些,没有发现你的说的问题,both (p < q) and (p > q) are
possible, depending on how the parameters are passed. The code below is
compiled with c++ 11.
#include
#include
#include
using namespace std;
void foo(int *p, int *q)
{
while (p cout << "p < q" < return;
}
cout << "p > q" << endl;
return;
}
int main() {
int *pa = new int(10);
int *pb = new int(20);
foo(pa, pb);
foo(pb, pa);
return 0;
}
======== output ==========
p < q
p > q
--------------------------------
Process exited with return value 0
Press any key to continue . . .
g*********e
发帖数: 14401
12
这跟参数值有关吧,&p 和 &q 可能大小确定
w**********o
发帖数: 140
13
1. save your code in foo.c
void foo(int *p, int *q)
{
while (p ...
}
2. gcc -S -o foo.s foo.c
3. vim foo.s
4. read the assembly.
or just use this if you are lazy: http://assembly.ynh.io/
c*****e
发帖数: 737
14
因为你的题目本来就是错的。
int* q = new int(10);
int* p = new int(10);
foo(p, q);
foo (q, p);

【在 r******l 的大作中提到】
: void foo(int *p, int *q)
: {
: while (p: ...
: }
: 说其中的while永远进不去,因为p: 远比q大12。这是为啥呢?什么地方有讲这种东西?有没有相关网页?多谢!

t****t
发帖数: 6806
15
exactly, 上面一堆人在讲什么cdecl, 拜托那是在比较&p和&q的情况下才会去看什么栈
方向ABI之类的东西.

【在 c*****e 的大作中提到】
: 因为你的题目本来就是错的。
: int* q = new int(10);
: int* p = new int(10);
: foo(p, q);
: foo (q, p);

1 (共1页)
进入JobHunting版参与讨论
相关主题
Interview questions, BloombergC++ Q42: (C22)
问个C++ virtual function的问题C++: what is the output? How to interpret it?
微软C++面试题C++问题
C++继承问题新手问个C++(Thinking in C++ source code)
amazon的那道题目c++ 程序一问
An example of strategy pattern问个面试题
one C++ question这个C++程序的运行结果是什么
请教C/C++小求教:这个程序为什么不能编译?
相关话题的讨论汇总
话题: int话题: foo话题: 概念话题: while话题: pb