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*(*)()) |
"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. |
thank you!
|
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. |
Quote:
"errno" is a global variable in libc |
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 |
- 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? |
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. |