LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-29-2004, 05:55 AM   #1
icoming
Member
 
Registered: Feb 2004
Posts: 96

Rep: Reputation: 15
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*(*)())
 
Old 05-29-2004, 06:33 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
"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.
 
Old 05-29-2004, 09:30 AM   #3
icoming
Member
 
Registered: Feb 2004
Posts: 96

Original Poster
Rep: Reputation: 15
thank you!
 
Old 05-29-2004, 11:52 AM   #4
icoming
Member
 
Registered: Feb 2004
Posts: 96

Original Poster
Rep: Reputation: 15
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.
 
Old 05-29-2004, 09:25 PM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Quote:
Quoting myself:
"errno" is a static variable in libc
This should off course be:
"errno" is a global variable in libc
 
Old 05-30-2004, 12:23 AM   #6
icoming
Member
 
Registered: Feb 2004
Posts: 96

Original Poster
Rep: Reputation: 15
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
 
Old 05-30-2004, 06:57 AM   #7
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
- 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?
 
Old 05-30-2004, 11:33 AM   #8
icoming
Member
 
Registered: Feb 2004
Posts: 96

Original Poster
Rep: Reputation: 15
the second program is a text-mode program.
and the first program does execute SigWinch() when the terminal is resized
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ProFTPd signal 15 error lookformeb Linux - Software 2 03-29-2004 09:41 PM
What is a Signal 11 error and how do I fix this? bigredmed Linux - Newbie 5 10-29-2003 02:07 PM
Mandrake 9.1 Signal 4 error? annorax Linux - Distributions 0 08-08-2003 10:06 AM
Signal 6: Unknown Signal <=> Error with MAYA4.X under Linux SOLVED!!!! Faeroon Linux - Software 9 05-09-2003 02:57 PM
Signal 11 error Rocky Linux - Newbie 1 10-24-2001 08:15 AM


All times are GMT -5. The time now is 06:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration