第二次通过时的段故障 [英] Seg Fault on 2nd Pass

查看:58
本文介绍了第二次通过时的段故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我正在接受一些一般性的建议。目前我有一些代码

应该运行FOR循环一定次数。每次读取

结构标记时如下:


for(i = 0; i< stamp_number; i ++)

{

printf("%g\ n",stamps [1] .scprod [2]);

....


现在在第一次传递时i = 0,整个循环运行正常。然而,在第二次通过时,我获得了一个Seg Fault,当读取上面的printf行时,我得到一个Seg Fault。

现在你可以看到从邮票中读取的值与

FOR循环参数但两次都是相同的,但不知何故第二次

时间读取同一行(当stmaps中的值没有时为

由其他代码改变了)我得到了一个Seg Fault。


因此,我只是在谈到如何做到这一点的想法?


亲切的问候,


Matt

Hello. I''m after some general advice. At the moment i have some code
that should run a FOR loop a set number of times. Each time the
structure stamps is read in as follows:

for( i = 0 ; i < stamp_number ; i++ )
{
printf("%g\n",stamps[1].scprod[2]);
....

Now on the first pass when i = 0 the whole loop runs fine. However
onthe 2nd pass, I get a Seg Fault when the printf line above is read.
Now as you can see the value read from stamps is not varying with the
FOR loop parameter but is the same both times, but somehow the second
time the same line is read (when the values in stmaps have not been
altered by the rest of the code) I get a Seg Fault.

Therefore, I''m just after some ideas regarding how this is possible?

Kind Regards,

Matt

推荐答案

Matt< ma*****@hotmail.comwrites:
Matt <ma*****@hotmail.comwrites:

你好。我正在接受一些一般性的建议。目前我有一些代码

应该运行FOR循环一定次数。每次读取

结构标记时如下:


for(i = 0; i< stamp_number; i ++)

{

printf("%g\ n",stamps [1] .scprod [2]);

...


现在在第一次传递时,当i = 0时,整个循环运行正常。然而,在第二次通过时,
,当读取上面的printf行时,我得到一个Seg Fault

现在你可以看到从邮票中读取的值不随着

FOR循环参数但两次都是相同的,但不知何故第二次

读取同一行的时间(当stmaps中的值没有为$ / b
由其余的代码改变了)我得到了一个Seg Fault。


因此,我只是在谈到如何做到这一点的一些想法?
Hello. I''m after some general advice. At the moment i have some code
that should run a FOR loop a set number of times. Each time the
structure stamps is read in as follows:

for( i = 0 ; i < stamp_number ; i++ )
{
printf("%g\n",stamps[1].scprod[2]);
...

Now on the first pass when i = 0 the whole loop runs fine. However
onthe 2nd pass, I get a Seg Fault when the printf line above is read
Now as you can see the value read from stamps is not varying with the
FOR loop parameter but is the same both times, but somehow the second
time the same line is read (when the values in stmaps have not been
altered by the rest of the code) I get a Seg Fault.

Therefore, I''m just after some ideas regarding how this is possible?



最可能的原因很简单,循环中的某些代码会破坏程序数据的b / b
。例如,未定义的访问通过胭脂

指针可能会更改''戳记'',以便邮票[1]变为无效,因为
会触发故障。真正的问题几乎总是在其他地方。


如果您的程序不大,请尝试将其剪切成可用的问题示例。如果它很大,它应该已经弥补了b $ b小块,可测试的碎片。使用测试程序挑起错误

只是练习导致问题的部分并发布一个

减少的版本!


-

Ben。

The most likely reason is simply that some code in the loop is messing
up you program''s data. For example, undefined access though a rouge
pointer could change ''stamps'' so that stamps[1] becomes invalid as
triggers the fault. The real problem is almost always somewhere else.

If your program is not large, try to cut it down into a postable
example of the problem. If it is large, it should already be made up
of small, testable, pieces. Provoke the error with a test program
that just exercises the piece that is causing the trouble and post a
cut-down version of that!

--
Ben.




" Matt" < ma ***** @ hotmail.comwrote in message

news:11 ********************** @ 57g2000hsv。 googlegro ups.com ...

"Matt" <ma*****@hotmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...

你好。我正在接受一些一般性的建议。目前我有一些代码

应该运行FOR循环一定次数。每次读取

结构标记时如下:


for(i = 0; i< stamp_number; i ++)

{

printf("%g\ n",stamps [1] .scprod [2]);

...


现在在第一次传递时,当i = 0时,整个循环运行正常。然而,在第二次通过时,我获得了一个Seg Fault,当读取上面的printf行时,我得到一个Seg Fault。

现在你可以看到从邮票中读取的值与

FOR循环参数但两次都是相同的,但不知何故第二次

时间读取同一行(当stmaps中的值没有时为

由其他代码改变了)我得到了一个Seg Fault。


因此,我只是在谈到如何做到这一点的一些想法?
Hello. I''m after some general advice. At the moment i have some code
that should run a FOR loop a set number of times. Each time the
structure stamps is read in as follows:

for( i = 0 ; i < stamp_number ; i++ )
{
printf("%g\n",stamps[1].scprod[2]);
...

Now on the first pass when i = 0 the whole loop runs fine. However
onthe 2nd pass, I get a Seg Fault when the printf line above is read.
Now as you can see the value read from stamps is not varying with the
FOR loop parameter but is the same both times, but somehow the second
time the same line is read (when the values in stmaps have not been
altered by the rest of the code) I get a Seg Fault.

Therefore, I''m just after some ideas regarding how this is possible?



你在循环中稍后做的其他事情导致问题,

可能是破坏邮票或其成员。

显示整个代码。

-

Fred L. Kleinschmidt

波音助理技术研究员

航空稳定性和控制计算

Something else you are doing later in the loop is causing the problem,
probably clobbering stamps or its members.
Show the whole code.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Aero Stability and Controls Computing


8月14日凌晨1点06分,Ben Bacarisse< ben.use ... @ bsb.me.ukwrote:
On Aug 14, 1:06 am, Ben Bacarisse <ben.use...@bsb.me.ukwrote:

Matt< matt ... @ hotmail.comwrites:
Matt <matt...@hotmail.comwrites:

你好。我正在接受一些一般性的建议。目前我有一些代码

应该运行FOR循环一定次数。每次读入

结构标记如下:
Hello. I''m after some general advice. At the moment i have some code
that should run a FOR loop a set number of times. Each time the
structure stamps is read in as follows:


for(i = 0; i< stamp_number; i ++)

{

printf("%g\ n",stamps [1] .scprod [2]);

。 ..
for( i = 0 ; i < stamp_number ; i++ )
{
printf("%g\n",stamps[1].scprod[2]);
...


现在在i = 0的第一次传递时,整个循环运行正常。然而,在第二次通过时,
,当读取上面的printf行时,我得到一个Seg Fault

现在你可以看到从邮票中读取的值不随着

FOR循环参数但两次都是相同的,但不知何故第二次

读取同一行的时间(当stmaps中的值没有为$ / b
由其余代码改变)我得到一个Seg Fault。
Now on the first pass when i = 0 the whole loop runs fine. However
onthe 2nd pass, I get a Seg Fault when the printf line above is read
Now as you can see the value read from stamps is not varying with the
FOR loop parameter but is the same both times, but somehow the second
time the same line is read (when the values in stmaps have not been
altered by the rest of the code) I get a Seg Fault.


因此,我只是在谈到如何做到这一点的一些想法?
Therefore, I''m just after some ideas regarding how this is possible?



最可能的原因很简单,循环中的某些代码会破坏程序数据的b / b
。例如,未定义的访问通过胭脂

指针可能会更改''戳记'',以便邮票[1]变为无效,因为
会触发故障。真正的问题几乎总是在其他地方。


如果您的程序不大,请尝试将其剪切成可用的问题示例。如果它很大,它应该已经弥补了b $ b小块,可测试的碎片。使用测试程序挑起错误

只是练习导致问题的部分并发布一个

减少的版本!


-

Ben。


The most likely reason is simply that some code in the loop is messing
up you program''s data. For example, undefined access though a rouge
pointer could change ''stamps'' so that stamps[1] becomes invalid as
triggers the fault. The real problem is almost always somewhere else.

If your program is not large, try to cut it down into a postable
example of the problem. If it is large, it should already be made up
of small, testable, pieces. Provoke the error with a test program
that just exercises the piece that is causing the trouble and post a
cut-down version of that!

--
Ben.



Rhe smal可测试的部分包含在我所拥有的许多单独的源文件中。

可悲的是,它们都是相互依赖的,很多行o在此特定功能达到
之前,fcode在主函数中执行了
。如果有任何用处,我已经完整地发布了FOR循环

以下你可以看看是否有任何变化,但我应该注意

那个我能找到的唯一相关的是stamps [i] .norm = sum; b ut

这是一个不同的子结构改为scprod。


我已经评论过GSL部件,所以很清楚每个部件在做什么。


for(i = 0; i< stamp_number; i ++)


{


printf("%g\ n",stamps [1] .scprod [2]); / *分段错误在这里

2来自我的循环* /


for(im = 1; im< = ncomps; im ++)


{


gsl_vector_set(check_vec,im,stamps [i] .scprod [im]); / *设置

check_vec [im] = stamps [i] .scprod [im] * /


for(jm = 1; jm< = im ; jm ++)


{


gsl_matrix_set(check_mat,im,jm,stamps [i] .mat [im]

[jm]); / *设置check_mat [im] [jm] = stamps [i] .mat [im] [jm] * /


}


}

gsl_matrix_view check_mat_view = gsl_matrix_view_array

(check_mat,ncomp_total + 1 + 100,ncomp_total + 1 + 100); / *

创建一个矢量视图* /

gsl_vector_view check_vec_view = gsl_vector_view_array

(check_vec,ncomp_total + 1 + 100); / *创建矩阵视图* /

gsl_linalg_LU_decomp(& check_mat_view.matrix,indx,& d); / *

因子方阵矩阵check_mat_view进入LU分解PA = LU * /


gsl_linalg_LU_svx(& check_mat_view.matrix,indx,

& check_vec_view.vector); / *解决方形系统* /


for(j = 0,sum = 0.0; j< ncomp_kernel; j ++)


{


sum + = gsl_vector_get(check_vec,j + 1)* sum_vectors [j]; / *

阅读check_vec [j + 1] * /


}


check_stack [i] =总和;

邮票[i] .norm = sum;

mean + = sum;

sigma + = sum * sum;


printf(" x:%iy:%i%lf \ n",stamps [i] .x,stamps [i] .y,sum);

}

亲切的问候,


Matt

Rhe smal testable pieces are in the many seperate source files I have.
Sadly they are all heavily inter-dependant and many lines o fcode are
executed in the main function before this particular function is
reached. If it is of any use, I''ve posted the FOR loop in its entirety
below so you can see if there are any changes, though I should note
that the only relevant one I can find is "stamps[i].norm = sum;" b ut
this is changing a different sub-structure to scprod.

I''ve commented the GSL parts so it is clear what each part is doing.

for( i = 0 ; i < stamp_number ; i++ )

{

printf("%g\n",stamps[1].scprod[2]); /* SEGMENTATION FAULT HERE ON
2ND PASS FROM i DO LOOP */

for( im = 1 ; im <= ncomps ; im++ )

{

gsl_vector_set( check_vec , im , stamps[i].scprod[im] ); /* Sets
check_vec[im] = stamps[i].scprod[im] */

for( jm = 1 ; jm <= im ; jm++ )

{

gsl_matrix_set( check_mat , im , jm , stamps[i].mat[im]
[jm] ); /* Sets check_mat[im][jm] = stamps[i].mat[im][jm] */

}

}

gsl_matrix_view check_mat_view = gsl_matrix_view_array
( check_mat , ncomp_total + 1 + 100 , ncomp_total + 1 + 100 ); /*
Create a vector view */
gsl_vector_view check_vec_view = gsl_vector_view_array
( check_vec , ncomp_total + 1 + 100 ); /* Create a matrix view */

gsl_linalg_LU_decomp( &check_mat_view.matrix , indx , &d ); /*
Factorise square matrix check_mat_view into LU decomposition PA=LU */

gsl_linalg_LU_svx( &check_mat_view.matrix , indx ,
&check_vec_view.vector ); /* Solve the square system */

for( j = 0 , sum = 0.0 ; j < ncomp_kernel ; j++ )

{

sum += gsl_vector_get( check_vec , j + 1 ) * sum_vectors[j]; /*
Read check_vec[j+1] */

}

check_stack[i] = sum;
stamps[i].norm = sum;
mean += sum;
sigma += sum * sum;

printf("x: %i y: %i %lf\n", stamps[i].x , stamps[i].y , sum );

}
Kind Regards,

Matt


这篇关于第二次通过时的段故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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