LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   there is an error when i use signal() in c++ (https://www.linuxquestions.org/questions/programming-9/there-is-an-error-when-i-use-signal-in-c-187258/)

icoming 05-29-2004 04:55 AM

there is an error when i use signal() in c++
 
my program is like this:
#include<iostream>
using namespace std;

#include<signal.h>

static void SigWinch(int errno)
{
cout<<"aaa"<<endl;
}

int main()
{
signal(SIGWINCH , SigWinch);
exit(0);
}

when i compile it with g++,there is an error as follow:
[zd@zd test]$ g++ -ggdb3 -o 17 17.cpp
17.cpp: In function `int main()':
17.cpp:13: invalid conversion from `void (*)(int*(*)())' to `void (*)(int)'

but the signal() is void (*signal (int signo , void (*func)(int)))(int)
why it want void (*)(int*(*)())

Hko 05-29-2004 05:33 AM

"errno" is a static variable in libc!
You can't use "errno" as an identifier for your own variables.
Just change "errno" into (almost) anything else, and your prog should be OK.

icoming 05-29-2004 08:30 AM

thank you!

icoming 05-29-2004 10:52 AM

but i still have a program.
i write an edit with c++,and want to use signal().
the part of my program is like this:
#include "All.h"
#include "Control.h"
#include "StrView.h"

StrView FirstView;

struct winsize GetWinSize()
{
struct winsize size;
if(ioctl(1 , TIOCGWINSZ , (char *)&size) < 0)
{
size.ws_col=0;
size.ws_row=0;
FirstView.DisplayCommand("TIOCGWINSZ error");
}
return size;
}

void SigWinch(int signo)
{
FirstView.WinSize=GetWinSize();
FirstView.Display(*(FirstView.str));
}

void SigAlrm(int signo)
{
}

int main (int argc , char *argv[])
{
try
{
if(argc == 1)
argv=NULL;
Control control(argv , argc);
signal(SIGWINCH , SigWinch);
signal(SIGALRM , SigAlrm);
move(0 , 0);
for(;!control.GetNowExit()
{
if(control.GetMode() == COMMANDMODE)
control.ReadCommand();
else
control.EditFile();
}
}
catch(FatalError error)
{
cout<<error.GetStr();
}
}

but when i change the size of window,the function SigWinch() is not executed.

Hko 05-29-2004 08:25 PM

Quote:

Quoting myself:
"errno" is a static variable in libc
This should off course be:
"errno" is a global variable in libc

icoming 05-29-2004 11:23 PM

i know.
so i changed the name of parameter
but there is still problem.
i have posted the program.
i don't know why SigWinch() wasn't execute

Hko 05-30-2004 05:57 AM

- Does the first program execute SigWinch() when you resize terminal?
- Is the second program a text-mode (console / xterm) program, or is it a graphical (X) program?

icoming 05-30-2004 10:33 AM

the second program is a text-mode program.
and the first program does execute SigWinch() when the terminal is resized


All times are GMT -5. The time now is 01:41 AM.