-   Programming (
-   -   there is an error when i use signal() in c++ (

icoming 05-29-2004 04:55 AM

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


static void SigWinch(int errno)

int main()
signal(SIGWINCH , SigWinch);

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)
FirstView.DisplayCommand("TIOCGWINSZ error");
return size;

void SigWinch(int signo)

void SigAlrm(int signo)

int main (int argc , char *argv[])
if(argc == 1)
Control control(argv , argc);
signal(SIGWINCH , SigWinch);
signal(SIGALRM , SigAlrm);
move(0 , 0);
if(control.GetMode() == COMMANDMODE)
catch(FatalError error)

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

Hko 05-29-2004 08:25 PM


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 09:56 PM.