简体   繁体   English

sigemptyset()正在覆盖下一个变量

[英]sigemptyset() is overwriting next variable

I have global variables 我有全局变量

int a[10];
struct sigaction act;
int b[10];

Whenever I call 每当我打电话

sigemptyset(&act.sa_mask); 

array a is getting corrupted. 数组a损坏。 I doubt if it is compiler issue. 我怀疑是否是编译器问题。 I am using CodeSourcery mips-linux-gnu-gcc version 4.5.2. 我正在使用CodeSourcery mips-linux-gnu-gcc版本4.5.2。 I compile using 我用编译

mips-linux-gnu-gcc -c -g -muclibc -pedantic -Wno-declaration-after-statement -std=gnu99 -G 0 -mips2 -msoft-float -mno-memcpy -fomit-frame-pointer -pipe -Wall -Wstrict-prototypes signal/signal.c

mips-linux-gnu-gcc -G 0 -msoft-float -static -o signal  signal.o

My complete code follows: 我完整的代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
int a[10];
struct sigaction act;
int b[10];


int main ();
int main ()
{
int i;
//initialize a and b
for(i = 0 ; i < 10;i++)
{
    a[i]=1;b[i]=1;
}

sigemptyset(&act.sa_mask);

//print
for(i = 0 ; i < 10;i++)
{
    printf("%d %d ",a[i],b[i]);
}

return 0;
}

I found that using the -muclibc option for compiling causes this issue. 我发现使用-muclibc选项进行编译会导致此问题。

You are showing the struct sigaction act after the a array, but in the code you mention a siginfo variable, not act . 您将在数组之后显示struct sigaction act ,但是在代码中提到了siginfo变量,而不是act

Could siginfo be declared before the a array ? 可以数组之前声明siginfo吗? Could you show what that function is doing ? 你能证明那个函数在做什么吗?

i found the answer I am not linking with -muclibc option 我找到了我不与-muclibc选项链接的答案

mips-linux-gnu-gcc -G 0 -msoft-float -static -muclibc -o signal  signal.o

will solve the problem 将解决问题

so while compiling it is is using sigset.h from uclibc and while executing it was executing code from libc( signal.c sigemptyset() ) 因此,在编译时,它使用的是来自uclibc的sigset.h,而在执行时则是从libc( signal.c sigemptyset() )执行代码

and if you digdown further _SIGSET_NWORDS for mips is 4 while for x86 it is 32 so sigemptyset() was running for 32 iteration instead of 4 如果进一步_SIGSET_NWORDS的mips是4,而x86是32,则sigemptyset()运行了32次迭代,而不是4次

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM