为什么一步一步调试,没关系 [英] why debug step by step, it s ok

查看:60
本文介绍了为什么一步一步调试,没关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个简单的程序:

#define __EXTENSIONS__

#include< stdio.h>

#include< string.h>

int main(){

char * buf =" 5/90/45" ;;

char * token;

char *持续时间;

printf(带有strtok()的tokenizing \%s\):\\ \\ n",buf);

if((token = strtok(buf," /"))!= NULL){

printf(" token = \"%s \" \ n",token);

while((token = strtok(NULL," /"))!= NULL){

printf(" token = \"%s \" \ n",token);

}

}

}


该程序滥用了这项工作,我知道,


******但为什么何时我是`gdb prog_name`并逐步执行,它是

好​​吗?

谢谢


baumann @ pan

Hi all,
I have one simple program:
#define __EXTENSIONS__
#include <stdio.h>
#include <string.h>
int main() {
char *buf="5/90/45";
char *token;
char *lasts;
printf("tokenizing \"%s\" with strtok():\n", buf);
if ((token = strtok(buf, "/")) != NULL) {
printf("token = \"%s\"\n", token);
while ((token = strtok(NULL, "/")) != NULL) {
printf("token = \"%s\"\n", token);
}
}
}

the program has abused the strok, i know it,

******but why when i `gdb prog_name` and execute step by step , it ''s
ok?
thanks

baumann@pan

推荐答案

baumann @ pan wrot e:
baumann@pan wrote:
大家好,


< code snipped>

该程序滥用了这条线索,我知道,<但是,为什么当我`gdb prog_name`并逐步执行时,它确定好了?
Hi all,

<code snipped>
the program has abused the strok, i know it,

******but why when i `gdb prog_name` and execute step by step , it ''s
ok?




未定义的行为正是如此:未定义。该代码在加利福尼亚可能有效,可能会崩溃,导致鼻子恶魔或导致泥石流。


重点是,你不知道。

Mark F. Haigh
mf*****@sbcglobal.net



Undefined behavior is exactly that: undefined. The code might work
fine, crash, generate nasal demons, or cause mudslides in California.

The point is, you don''t know.
Mark F. Haigh
mf*****@sbcglobal.net


baumann @ pan写道:
baumann@pan wrote:
大家好,

我有一个简单的程序:
#define __EXTENSIONS__
#include< stdio.h>
#include< string.h>

int main(){
char * BUF = << 5/90/45 QUOT ;;
buf是指向字符串常量的指针

char buf [] =" 5/90/45"

是正确的。

char * token;
char * lasts;

printf(" tokenizing \"%s \" with strtok():\ n",buf);
if((token = strtok(buf," /"))!= NULL){
strtok更改buf的内容,因此内容必须可更改。

printf(" token = \"%s \" \ n",token);
while((token = strtok(NULL," /"))!= NULL){
printf(" token = \"%s \" \ n",token);
}
}
}
该程序滥用了这项工作,我知道,
******但为什么当我`gdb prog_name`并逐步执行时,它确定没问题?

谢谢

baumann @ pan
Hi all,
I have one simple program:
#define __EXTENSIONS__
#include <stdio.h>
#include <string.h>
int main() {
char *buf="5/90/45"; buf is a pointer to a string constant
char buf[] = "5/90/45"
is correct.
char *token;
char *lasts;
printf("tokenizing \"%s\" with strtok():\n", buf);
if ((token = strtok(buf, "/")) != NULL) { strtok changes the content of buf, so the content must be changeable.
printf("token = \"%s\"\n", token);
while ((token = strtok(NULL, "/")) != NULL) {
printf("token = \"%s\"\n", token);
}
}
}

the program has abused the strok, i know it,

******but why when i `gdb prog_name` and execute step by step , it ''s
ok?
thanks

baumann@pan




-

Michael Knaup



--
Michael Knaup


你没有回答我的问题,


i在另一个帖子帖子中回答了这个问题。


并且在实践中,我发现在调试和执行一步一步时,编程

运行良好。

Michael Knaup写道:
you donn''t answer my question,

i have answered the question in another post thread.

and in practice, i found when in debug and exec step by step, the prog
runs well.
Michael Knaup wrote:
baumann @ pan写道:
baumann@pan wrote:
大家好,

我有一个简单的程序:
#define __EXTENSIONS__
#include< stdio.h>
#include< string.h>

int main(){
char * buf =" 5/90/45" ;;
Hi all,
I have one simple program:
#define __EXTENSIONS__
#include <stdio.h>
#include <string.h>
int main() {
char *buf="5/90/45";


buf是一个指向字符串常量的指针
char buf [] =" 5/90/45"
是正确的。


buf is a pointer to a string constant
char buf[] = "5/90/45"
is correct.

char * token;
char *持续时间;

printf(" tokenizing \"%s \"与strtok():\ n",buf);
if((token = strtok(buf," /"))!= NULL){
char *token;
char *lasts;
printf("tokenizing \"%s\" with strtok():\n", buf);
if ((token = strtok(buf, "/")) != NULL) {


strtok更改内容of buf,所以内容必须是可更改的。


strtok changes the content of buf, so the content must be changeable.

printf(" token = \"%s\" \ n",token);
while((token = strtok(NULL," /"))!= NULL){
printf(" token = \"%s \" \ n",token);
}
}


这个程序滥用了这条道路,我知道,

******但为什么当我是`gdb prog_name`然后一步一步地执行,好吧?

谢谢

baumann @ pan
printf("token = \"%s\"\n", token);
while ((token = strtok(NULL, "/")) != NULL) {
printf("token = \"%s\"\n", token);
}
}
}

the program has abused the strok, i know it,

******but why when i `gdb prog_name` and execute step by step , it ''s
ok?
thanks

baumann@pan



-
Michael Knaup



--
Michael Knaup






这篇关于为什么一步一步调试,没关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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