调试...解除引用,&等等 [英] debugging... dereferencing, & etc.

查看:52
本文介绍了调试...解除引用,&等等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个有趣的问题,我认为这是非常健康的要检查......这个程序正在调查中:


- - - - - - -

#include< iostream>

使用命名空间std;


#define DAYS 7


int main()

{

void bsort(char **,int);


char * p_string [DAYS] = {" Sunday","星期一,星期二,

星期三,星期四,

星期五,星期六};


cout<< 在对指针进行排序之前:\ n \ nn;;

for(int j = 0; j< DAYS; j ++)

cout<< p_string [j]<< endl;


bsort(p_string,DAYS);


cout<< 在对指针进行排序之后:\ n \ n" ;;

for(int j = 0; j< DAYS; j ++)

cout<< p_string [j]<<结束;


返回0;

}


void bsort(char ** ptr,int n)

{

无效订单(char *&,char *&);

int j,k;


for(j = 0; j< n-1; j ++)

for(k = j + 1; k< n; k ++)

order (ptr [j],ptr [k]);

}


无效订单(char *& pp1,char *& pp2)

{

if(strcmp(pp1,pp2)> 0)

{

char * tempptr = pp1;

pp1 = pp2;

pp2 = tempptr;

}

}

- - - - -


运行正常(只需复制/粘贴)......


有两个posibilites(至少)作品:


上面有bsort里面的原型:


1)void order(char *&,char *&);


....和:


无效订单(char *& pp1,char *& pp2)

{

if(strcmp(pp1,pp2)> 0)

{

char * tempptr = pp1;

pp1 = pp2;

pp2 = tempptr;

}

}


- - - - - - - - - - - - - - - - - - - - - -

但....我也可以(原型instide bsort):


2)无效订单( char *,char *);


....和:


无效订单(char * pp1,char * pp2)

{

if(strcmp(pp1,pp2)> 0)

{

char * tempptr = pp1;

pp1 = pp2;

pp2 = tempptr; < br $>
}

}


这也有效...


- - - - - - - - - - -


1和2之间的区别在于,如果我在
order()中放置一个断点,我的调试器会显示使用方法...


1)pp1 = @ 0xbffffa60,pp2 = @ 0xbffffa64


并使用其他方法:


2)pp1 = 0xde80(星期日),pp2 = 0xde8c(星期一)


- - - - - - - - - - -


所以方法1和方法2的区别是???我不太明白

它,但显然程序有两种不同的工作方式。

我看到方法2直接显示(星期日)或(星期一)或调试器内的任何来自

的东西。方法1在地址前面有一个奇怪的@

并且它没有显示(星期日/星期一)。什么是@ -thing?我会假设

这个& -means别名来/引用????


这个程序可能还有其他方法可以工作......如果

有人想告诉,继续,我希望我能学会理解它:-)

祝你好运/ Med venlig hilsen

Martin J?rgensen


-

----------------------- -------------------------------------------------- -

Martin J?rgensen的家 - http://www.martinjoergensen .dk

推荐答案

Martin J?rgensen写道:
Martin J?rgensen wrote:
我有一个有趣的问题,我认为这是非常健康的检查...正在调查此程序:

- - - - - - -
#include< iostream>
使用命名空间std;

#define DAYS 7


{/ b}

* p_string [DAYS] = {" Sunday"," Monday"," Tuesday",


应该是


char const * p_strings [DAYS] = ...


(注意''const'')。

" Wednesday",Thursday,
Friday,Saturday};

cout<< 在对指针进行排序之前:\ n \ n" ;;
for(int j = 0; j< DAYS; j ++)
cout<< p_string [j]<< endl;

bsort(p_string,DAYS);

cout<< 在对指针进行排序之后:\ n \ n";
for(int j = 0; j< DAYS; j ++)
cout<< p_string [j]<< endl;

返回0;
}

void bsort(char ** ptr,int n)


void bsort(char const ** pptr,int n)

{
void order(char *&,char *&);


无效订单(char const *&,char const *&);

int j,k;

(j = 0; j for(k = j + 1; k order(ptr [j],ptr [k]);


void order(char const *& pp1,char const *& pp2)

{
if(strcmp(pp1,pp2)> 0)
{* char * tempptr = pp1;
pp1 = pp2;
pp2 = tempptr;


std :: swap(pp1,pp2);

}
}
- - - - -
<它运行正常(只是复制/粘贴)...

有2个posibilites(至少)有效:

上面有bsort里面的原型:

1)无效订单(char *&,char *&);

......和:

无效订单(char *& ; pp1,char *& pp2)
{
if(strcmp(pp1,pp2)> 0)
{* char * tempptr = pp1;
pp1 = pp2;
pp2 = tempptr;
}
}

- - - - - - - - - - - - - - - - - - - - - -
但....我也可以(原型instide bsort):

2)无效顺序(char *,char *);

.. 。和:

无效顺序(char * pp1,char * pp2)
{
if(strcmp(pp1,pp2)> 0)
{
char * tempptr = pp1;
pp1 = pp2;
pp2 = tempptr;
}
}

这也有效......


不,它不是。你试过吗?

- - - - - - - - - - -

1和2的区别在于如果我在里面放置一个断点
order(),我的调试器显示使用方法...

1)pp1 = @ 0xbffffa60,pp2 = @ 0xbffffa64

并使用其他方法:

2)pp1 = 0xde80(星期日),pp2 = 0xde8c(星期一)

- - - - - - - - - - -

所以区别方法1和2是???


运行它们。 1对指针排序吗? 2?

我不太了解它,但显然有两种不同的方式可以使用
程序。


嗯?这是两个不同的程序。

我看到方法2直接显示(星期日)或
(星期一)或调试器内的任何内容。


谁在乎调试器?这项计划的输出是什么?

你真的打扰看它吗?

方法1在地址前面有一个奇怪的
@并且它没有显示(星期日/星期一)。什么是@ -thing?我会假设这个& -means别名为/引用????


在新闻组中询问与你的调试器有关的问题。

这个程序可能还有其他方法可以使用....如果
任何人我想告诉,继续,我希望我能学会理解它
: - )
I have a "funny" question, which I think is pretty "healthy" to
examine... This program is being investigated:

- - - - - - -
#include <iostream>
using namespace std;

#define DAYS 7

int main()
{
void bsort(char **, int);

char *p_string[DAYS] = {"Sunday", "Monday", "Tuesday",
Ought to be

char const *p_strings[DAYS] = ...

(note the ''const'').
"Wednesday", "Thursday",
"Friday", "Saturday"};

cout << "Before sorting the pointers:\n\n";
for(int j=0; j<DAYS; j++)
cout << p_string[j] << endl;

bsort(p_string, DAYS);

cout << "After sorting the pointers:\n\n";
for(int j=0; j<DAYS; j++)
cout << p_string[j] << endl;

return 0;
}

void bsort(char **ptr, int n)
void bsort(char const **pptr, int n)
{
void order(char*&, char*&);
void order(char const*&, char const*&);
int j,k;

for(j=0; j<n-1; j++)
for(k=j+1; k<n; k++)
order(ptr[j], ptr[k]);
}

void order(char*& pp1, char*& pp2)
void order(char const*& pp1, char const*& pp2)
{
if( strcmp(pp1, pp2) > 0)
{
char *tempptr = pp1;
pp1 = pp2;
pp2 = tempptr;
std::swap(pp1, pp2);
}
}
- - - - -

It runs fine (just copy/paste)...

There are 2 posibilites (at least) that works:

The above has prototype inside bsort:

1) void order(char*&, char*&);

... and:

void order(char*& pp1, char*& pp2)
{
if( strcmp(pp1, pp2) > 0)
{
char *tempptr = pp1;
pp1 = pp2;
pp2 = tempptr;
}
}

- - - - - - - - - - - - - - - - - - - - - -
But.... I can also do (prototype instide bsort):

2) void order(char*, char*);

... and:

void order(char* pp1, char* pp2)
{
if( strcmp(pp1, pp2) > 0)
{
char *tempptr = pp1;
pp1 = pp2;
pp2 = tempptr;
}
}

This also works...
No, it doesn''t. Did you try it?
- - - - - - - - - - -

The difference between 1 and 2 is that if I place a breakpoint inside
order(), my debugger shows that using method...

1) pp1 = @0xbffffa60, pp2 = @0xbffffa64

and using the other method:

2) pp1 = 0xde80 (sunday), pp2 = 0xde8c (monday)

- - - - - - - - - - -

So the difference between method 1 and 2 is???
Run them. Does 1 sort the pointers? Does 2?
I didn''t quite
understand it, but obviously there are 2 different ways in which the
program works.
Huh? These are two different programs.
I see that method 2 directly shows (sunday) or
(monday) or whatever from inside the debugger.
Who cares about the debugger? What''s the output of the program?
Have you actually bothered to look at it?
Method 1 has a strange
@ in front of the address and it doesn''t show (sunday/monday). What''s
that @-thing? I would assume this &-means alias to/reference to????
Ask in the newsgroup that deals with your debugger.
There are probably also other methods this program could work.... If
anyone wants to tell, go on and I hope I can learn to understand it
:-)




我不知道你的意思。


V

-

请在邮寄回复时从我的地址中删除资金



I have no idea what you mean.

V
--
Please remove capital As from my address when replying by mail


Victor Bazarov写道:

-snip-
Victor Bazarov wrote:
-snip-
在新闻组中询问处理您的调试器。
Ask in the newsgroup that deals with your debugger.




我不认为你在C ++编程方面能够理解

代码...

祝你好运/ Med venlig hilsen

Martin J?rgensen


-

---------------- -------------------------------------------------- ---------

Martin J?rgensen的主页 - HTTP:// WWW。 martinjoergensen.dk




Martin J?rgensen skrev:

Martin J?rgensen skrev:
Victor Bazarov写道:
-snip-
Victor Bazarov wrote:
-snip-
在新闻组中询问处理你的调试器。
我认为你对C ++编程不够好理解
代码......
Ask in the newsgroup that deals with your debugger.
I don''t think you''re good enough at C++ programming to understand the
code...



当然,如果你按照这个新闻组的最短时间来获得
时间,你就会知道那个Victor对C ++的了解已经足够了。

可以回答这里的任何事情。

快速浏览一下你的代码就好像让我们相信你一样

应该花一些时间学习C ++,这样你有一天可能会有一个C ++程序来提问。


/ Peter

最好的问候/ Med venlig hilsen
Martin J?rgensen

-
---------------- -------------------------------------------------- ---------
3月的家tin J?rgensen - http://www.martinjoergensen.dk






这篇关于调试...解除引用,&amp;等等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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