Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Thank heaven for startups; without them we'd never have any advances." -- Seymour Cray


devel / comp.unix.programmer / Re: Question about Linux/gcc and the signal() function prototype.

SubjectAuthor
* Question about Linux/gcc and the signal() function prototype.Kenny McCormack
`* Re: Question about Linux/gcc and the signal() function prototype.Ralf Fassel
 `* Re: Question about Linux/gcc and the signal() function prototype.Kenny McCormack
  +* Re: Question about Linux/gcc and the signal() function prototype.Nicolas George
  |`- Re: Question about Linux/gcc and the signal() function prototype.Kenny McCormack
  +- Re: Question about Linux/gcc and the signal() function prototype.Scott Lurndal
  `* Re: Question about Linux/gcc and the signal() function prototype.Rainer Weikusat
   `* Re: Question about Linux/gcc and the signal() function prototype.Kenny McCormack
    `* Re: Question about Linux/gcc and the signal() function prototype.Kaz Kylheku
     +- Re: Question about Linux/gcc and the signal() function prototype.Richard Damon
     `- Re: Question about Linux/gcc and the signal() function prototype.Rainer Weikusat

1
Question about Linux/gcc and the signal() function prototype.

<tlq9hg$fuhb$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17355&group=comp.unix.programmer#17355

  copy link   Newsgroups: comp.unix.programmer comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer,comp.lang.c
Subject: Question about Linux/gcc and the signal() function prototype.
Date: Fri, 25 Nov 2022 11:39:28 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tlq9hg$fuhb$1@news.xmission.com>
Injection-Date: Fri, 25 Nov 2022 11:39:28 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="522795"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 25 Nov 2022 11:39 UTC

Note: This question is very Linux and gcc specific. You've been warned!
Also, don't bother picking nits like how main() is declared or whether or
not to use the word "stack" in polite company. Thanks.

I have a small C program that looks basically like:

#define _GNU_SOURCE
#include <signal.h>

....

sighandler_t myhandler(int sig)
{ ...
}

int main(void)
{ ....
signal(1,myhandler);
....
}

I compile with the usual: -W -Wall -Werror
and get these errors:

$ gcc ...
MyTest.c: In function 'main':
MyTest.c:22:40: error: passing argument 2 of 'signal' from incompatible pointer type [-Werror]
signal(1,myhandler);
^
In file included from MyTest.c:7:0:
/usr/include/signal.h:102:23: note: expected '__sighandler_t' but argument is of type 'void (* (*)(int))(int)'
extern __sighandler_t signal (int __sig, __sighandler_t __handler)
^

Now, I can make this go away in either of two ways:

1) Change the call to signal to:

signal(1,(sighandler_t) myhandler);
or
2) Remove the #define _GNU_SOURCE and then:
a) Declare myhandler as "sig_t" instead of "sighandler_t".
b) Change the call to signal to:
signal(1,(sig_t) myhandler);

But the point is that in either case, a cast in the signal() call seems
to be required. Why is this?

Note that the myhandler() function is declared/defined before main(), so it
should "just work", shouldn't it?

--
Joni Ernst (2014): Obama should be impeached because 2 people have died of Ebola.
Joni Ernst (2020): Trump is doing great things, because only 65,000 times as many people have died of COVID-19.

Josef Stalin (1947): When one person dies, it is a tragedy; when a million die, it is merely statistics.

Re: Question about Linux/gcc and the signal() function prototype.

<ygazgcftf5r.fsf@akutech.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17356&group=comp.unix.programmer#17356

  copy link   Newsgroups: comp.unix.programmer comp.lang.c
Followup: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.unix.programmer,comp.lang.c
Subject: Re: Question about Linux/gcc and the signal() function prototype.
Followup-To: comp.unix.programmer
Date: Fri, 25 Nov 2022 13:03:12 +0100
Lines: 36
Message-ID: <ygazgcftf5r.fsf@akutech.de>
References: <tlq9hg$fuhb$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net XmSszI7azf9isFKXCKPGgwG4CPmqD0uIMmYGRYYdqNltXxqQ0=
Cancel-Lock: sha1:UQOtEQIPkQAAeVw7kYxR3qPh+o4= sha1:/tq6cIP6avAdF4YfSZdplZPQvAo=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Fri, 25 Nov 2022 12:03 UTC

* gazelle@shell.xmission.com (Kenny McCormack)
| Note: This question is very Linux and gcc specific. You've been warned!
| Also, don't bother picking nits like how main() is declared or whether or
| not to use the word "stack" in polite company. Thanks.
>
| I have a small C program that looks basically like:
>
| #define _GNU_SOURCE
| #include <signal.h>
>
| ...
>
| sighandler_t myhandler(int sig)
| {
| ...
| }

I think that according to signal(2) that should rather be

void myhandler(int sig) {
...
}

NAME
signal - ANSI C signal handling
SYNOPSIS
#include <signal.h>
typedef void (*sighandler_t)(int);

Note that 'sighandler_t' is the typedef for the _signal handler_ (to be
used in the declaration of signal()), not the return value of the signal
handler. The return value of the signal handler is void, taking one
integer argument.

R'

Re: Question about Linux/gcc and the signal() function prototype.

<tlqce3$fuhb$2@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17357&group=comp.unix.programmer#17357

  copy link   Newsgroups: comp.unix.programmer comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer,comp.lang.c
Subject: Re: Question about Linux/gcc and the signal() function prototype.
Date: Fri, 25 Nov 2022 12:28:51 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tlqce3$fuhb$2@news.xmission.com>
References: <tlq9hg$fuhb$1@news.xmission.com> <ygazgcftf5r.fsf@akutech.de>
Injection-Date: Fri, 25 Nov 2022 12:28:51 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="522795"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 25 Nov 2022 12:28 UTC

In article <ygazgcftf5r.fsf@akutech.de>, Ralf Fassel <ralfixx@gmx.de> wrote:
....
>I think that according to signal(2) that should rather be
>
> void myhandler(int sig) {
> ...
> }
>
>
> NAME
> signal - ANSI C signal handling
> SYNOPSIS
> #include <signal.h>
> typedef void (*sighandler_t)(int);
>
>Note that 'sighandler_t' is the typedef for the _signal handler_ (to be
>used in the declaration of signal()), not the return value of the signal
>handler. The return value of the signal handler is void, taking one
>integer argument.

Yes, thanks. That seems to fix things.

The funny thing is that (at least on my system), nowhere in "man signal"
does it actually tell you how to declare the signal handler function (that
is, as simply "void"). You could say that this is implicit in saying that
sighandler_t is a pointer to a void function, so the thing must itself be a
void function.

That's the C way...

All of this seems to be an artifact of the fact that functions and pointers
to functions are (basically) the same thing. This isn't true for any other
type of object.

--
Trump - the President for the rest of us.

https://www.youtube.com/watch?v=JSkUJKgdcoE

Re: Question about Linux/gcc and the signal() function prototype.

<6380bd9d$0$3065$426a74cc@news.free.fr>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17358&group=comp.unix.programmer#17358

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!cleanfeed1-a.proxad.net!nnrp2-1.free.fr!not-for-mail
Newsgroups: comp.unix.programmer
From: nicolas$george@salle-s.org (Nicolas George)
Subject: Re: Question about Linux/gcc and the signal() function prototype.
Sender: george@phare.invalid (Nicolas George)
X-Newsreader: Flrn (0.9.20070704)
References: <tlq9hg$fuhb$1@news.xmission.com> <ygazgcftf5r.fsf@akutech.de> <tlqce3$fuhb$2@news.xmission.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=utf-8
Date: 25 Nov 2022 13:05:33 GMT
Lines: 26
Message-ID: <6380bd9d$0$3065$426a74cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 25 Nov 2022 14:05:33 CET
NNTP-Posting-Host: 129.199.129.80
X-Trace: 1669381533 news-3.free.fr 3065 129.199.129.80:60224
X-Complaints-To: abuse@proxad.net
 by: Nicolas George - Fri, 25 Nov 2022 13:05 UTC

Kenny McCormack, dans le message <tlqce3$fuhb$2@news.xmission.com>, a
écrit :
> The funny thing is that (at least on my system), nowhere in "man signal"
> does it actually tell you how to declare the signal handler function (that
> is, as simply "void").

SYNOPSIS
#include <signal.h>

typedef void (*sighandler_t)(int);

sighandler_t signal(int signum, sighandler_t handler);

All we need to know is there.

Except…

> That's the C way...

Yes, knowledge of the C programming language, how to read type declarations
and so on, is an implicit prerequisite.

> All of this seems to be an artifact of the fact that functions and pointers
> to functions are (basically) the same thing.

No they are not.

Re: Question about Linux/gcc and the signal() function prototype.

<tlqhsi$g48c$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17359&group=comp.unix.programmer#17359

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer
Subject: Re: Question about Linux/gcc and the signal() function prototype.
Date: Fri, 25 Nov 2022 14:01:54 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tlqhsi$g48c$1@news.xmission.com>
References: <tlq9hg$fuhb$1@news.xmission.com> <ygazgcftf5r.fsf@akutech.de> <tlqce3$fuhb$2@news.xmission.com> <6380bd9d$0$3065$426a74cc@news.free.fr>
Injection-Date: Fri, 25 Nov 2022 14:01:54 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="528652"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 25 Nov 2022 14:01 UTC

In article <6380bd9d$0$3065$426a74cc@news.free.fr>,
Nicolas George <nicolas$george@salle-s.org> wrote:
>Kenny McCormack, dans le message <tlqce3$fuhb$2@news.xmission.com>, a
> crit:
>> The funny thing is that (at least on my system), nowhere in "man signal"
>> does it actually tell you how to declare the signal handler function (that
>> is, as simply "void").
>
>SYNOPSIS
> #include <signal.h>
>
> typedef void (*sighandler_t)(int);
>
> sighandler_t signal(int signum, sighandler_t handler);
>
>All we need to know is there.
>
>Except
>
>> That's the C way...
>
>Yes, knowledge of the C programming language, how to read type declarations
>and so on, is an implicit prerequisite.
>
>> All of this seems to be an artifact of the fact that functions and pointers
>> to functions are (basically) the same thing.
>
>No they are not.

What a totally stupid response.

You hit all the marks. Congrats.

--
I love the poorly educated.

Re: Question about Linux/gcc and the signal() function prototype.

<3u6gL.4180$lhOe.1802@fx06.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17360&group=comp.unix.programmer#17360

  copy link   Newsgroups: comp.unix.programmer comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx06.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Question about Linux/gcc and the signal() function prototype.
Newsgroups: comp.unix.programmer,comp.lang.c
References: <tlq9hg$fuhb$1@news.xmission.com> <ygazgcftf5r.fsf@akutech.de> <tlqce3$fuhb$2@news.xmission.com>
Lines: 31
Message-ID: <3u6gL.4180$lhOe.1802@fx06.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 25 Nov 2022 16:57:35 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 25 Nov 2022 16:57:35 GMT
X-Received-Bytes: 1918
 by: Scott Lurndal - Fri, 25 Nov 2022 16:57 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:
>In article <ygazgcftf5r.fsf@akutech.de>, Ralf Fassel <ralfixx@gmx.de> wrote:
>...
>>I think that according to signal(2) that should rather be
>>
>> void myhandler(int sig) {
>> ...
>> }
>>
>>
>> NAME
>> signal - ANSI C signal handling
>> SYNOPSIS
>> #include <signal.h>
>> typedef void (*sighandler_t)(int);
>>
>>Note that 'sighandler_t' is the typedef for the _signal handler_ (to be
>>used in the declaration of signal()), not the return value of the signal
>>handler. The return value of the signal handler is void, taking one
>>integer argument.
>
>Yes, thanks. That seems to fix things.
>
>The funny thing is that (at least on my system), nowhere in "man signal"
>does it actually tell you how to declare the signal handler function (that
>is, as simply "void"). You could say that this is implicit in saying that
>sighandler_t is a pointer to a void function, so the thing must itself be a
>void function.

FWIW, when using unix, linux or any POSIX based system, I'd recommend
using 'sigaction' rather than 'signal'.

Re: Question about Linux/gcc and the signal() function prototype.

<87lenwfuq4.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17361&group=comp.unix.programmer#17361

  copy link   Newsgroups: comp.unix.programmer comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer,comp.lang.c
Subject: Re: Question about Linux/gcc and the signal() function prototype.
Date: Sun, 27 Nov 2022 12:27:31 +0000
Lines: 16
Message-ID: <87lenwfuq4.fsf@doppelsaurus.mobileactivedefense.com>
References: <tlq9hg$fuhb$1@news.xmission.com> <ygazgcftf5r.fsf@akutech.de>
<tlqce3$fuhb$2@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net j2qXXZC23uiSiiPJ7J7PDQF2Py3tj7GWSU4MU5juwbe6dT1aI=
Cancel-Lock: sha1:C2JlZuX8pRF0GOwbr9oMVMgbnYo= sha1:3M5OHuA++uTPRblUXKOxa7pimxA=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Sun, 27 Nov 2022 12:27 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:

[sighandler_t confusion]

> All of this seems to be an artifact of the fact that functions and pointers
> to functions are (basically) the same thing. This isn't true for any other
> type of object.

It's basically the same as with array types: An object which has a function
type is automatically converted to a pointer to a function when used as
argument of something. But they're nevertheless distinct. Stevens uses

typedef void sighandler(int);
sighandler *signal(int, sighandler *);

in newer editions of APUE.

Re: Question about Linux/gcc and the signal() function prototype.

<tlvncc$im4v$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17363&group=comp.unix.programmer#17363

  copy link   Newsgroups: comp.unix.programmer comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer,comp.lang.c
Subject: Re: Question about Linux/gcc and the signal() function prototype.
Date: Sun, 27 Nov 2022 13:06:20 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tlvncc$im4v$1@news.xmission.com>
References: <tlq9hg$fuhb$1@news.xmission.com> <ygazgcftf5r.fsf@akutech.de> <tlqce3$fuhb$2@news.xmission.com> <87lenwfuq4.fsf@doppelsaurus.mobileactivedefense.com>
Injection-Date: Sun, 27 Nov 2022 13:06:20 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="612511"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sun, 27 Nov 2022 13:06 UTC

In article <87lenwfuq4.fsf@doppelsaurus.mobileactivedefense.com>,
Rainer Weikusat <rweikusat@talktalk.net> wrote:
>gazelle@shell.xmission.com (Kenny McCormack) writes:
>
>[sighandler_t confusion]
>
>> All of this seems to be an artifact of the fact that functions and pointers
>> to functions are (basically) the same thing. This isn't true for any other
>> type of object.
>
>It's basically the same as with array types: An object which has a function
>type is automatically converted to a pointer to a function when used as
>argument of something. But they're nevertheless distinct. Stevens uses
>
>typedef void sighandler(int);
>sighandler *signal(int, sighandler *);
>
>in newer editions of APUE.

Yes. That makes more sense.

Probably won't ever get fixed, though.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/WeekendAwayFromHome

Re: Question about Linux/gcc and the signal() function prototype.

<20221127164105.872@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17364&group=comp.unix.programmer#17364

  copy link   Newsgroups: comp.unix.programmer comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.programmer,comp.lang.c
Subject: Re: Question about Linux/gcc and the signal() function prototype.
Date: Mon, 28 Nov 2022 00:43:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <20221127164105.872@kylheku.com>
References: <tlq9hg$fuhb$1@news.xmission.com> <ygazgcftf5r.fsf@akutech.de>
<tlqce3$fuhb$2@news.xmission.com>
<87lenwfuq4.fsf@doppelsaurus.mobileactivedefense.com>
<tlvncc$im4v$1@news.xmission.com>
Injection-Date: Mon, 28 Nov 2022 00:43:35 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="b5754ebb8d9c05906acdc6ca1b32bc37";
logging-data="1888136"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lNxVUlth/U0FosMusOG9SJGP7SRAOEPQ="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:PULG12yl0IllbY7pbMVF8aNGeV8=
 by: Kaz Kylheku - Mon, 28 Nov 2022 00:43 UTC

On 2022-11-27, Kenny McCormack <gazelle@shell.xmission.com> wrote:
> In article <87lenwfuq4.fsf@doppelsaurus.mobileactivedefense.com>,
> Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>gazelle@shell.xmission.com (Kenny McCormack) writes:
>>
>>[sighandler_t confusion]
>>
>>> All of this seems to be an artifact of the fact that functions and pointers
>>> to functions are (basically) the same thing. This isn't true for any other
>>> type of object.
>>
>>It's basically the same as with array types: An object which has a function
>>type is automatically converted to a pointer to a function when used as
>>argument of something. But they're nevertheless distinct. Stevens uses
>>
>>typedef void sighandler(int);
>>sighandler *signal(int, sighandler *);
>>
>>in newer editions of APUE.
>
> Yes. That makes more sense.
>
> Probably won't ever get fixed, though.

With sighandler defined that way, you can do this:

sighandler myhandler; // forward declaration of your handler

void myhandler(int) // ... but no way of using sighandler for defining
{
}

It has little value compared to just making a typedef for the pointer.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Question about Linux/gcc and the signal() function prototype.

<_bVgL.117758$8875.113548@fx13.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17365&group=comp.unix.programmer#17365

  copy link   Newsgroups: comp.unix.programmer comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx13.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.5.0
Subject: Re: Question about Linux/gcc and the signal() function prototype.
Newsgroups: comp.unix.programmer,comp.lang.c
References: <tlq9hg$fuhb$1@news.xmission.com> <ygazgcftf5r.fsf@akutech.de>
<tlqce3$fuhb$2@news.xmission.com>
<87lenwfuq4.fsf@doppelsaurus.mobileactivedefense.com>
<tlvncc$im4v$1@news.xmission.com> <20221127164105.872@kylheku.com>
From: Richard@Damon-Family.org (Richard Damon)
Content-Language: en-US
In-Reply-To: <20221127164105.872@kylheku.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 38
Message-ID: <_bVgL.117758$8875.113548@fx13.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sun, 27 Nov 2022 21:39:54 -0500
X-Received-Bytes: 2455
 by: Richard Damon - Mon, 28 Nov 2022 02:39 UTC

On 11/27/22 7:43 PM, Kaz Kylheku wrote:
> On 2022-11-27, Kenny McCormack <gazelle@shell.xmission.com> wrote:
>> In article <87lenwfuq4.fsf@doppelsaurus.mobileactivedefense.com>,
>> Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>> gazelle@shell.xmission.com (Kenny McCormack) writes:
>>>
>>> [sighandler_t confusion]
>>>
>>>> All of this seems to be an artifact of the fact that functions and pointers
>>>> to functions are (basically) the same thing. This isn't true for any other
>>>> type of object.
>>>
>>> It's basically the same as with array types: An object which has a function
>>> type is automatically converted to a pointer to a function when used as
>>> argument of something. But they're nevertheless distinct. Stevens uses
>>>
>>> typedef void sighandler(int);
>>> sighandler *signal(int, sighandler *);
>>>
>>> in newer editions of APUE.
>>
>> Yes. That makes more sense.
>>
>> Probably won't ever get fixed, though.
>
> With sighandler defined that way, you can do this:
>
> sighandler myhandler; // forward declaration of your handler
>
> void myhandler(int) // ... but no way of using sighandler for defining
> {
> }
>
> It has little value compared to just making a typedef for the pointer.
>

The one advantage is if the definition disagrees with the forward
declaration, you will get a diagnostic, likely an error.

Re: Question about Linux/gcc and the signal() function prototype.

<87lenvuwq6.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17366&group=comp.unix.programmer#17366

  copy link   Newsgroups: comp.unix.programmer comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer,comp.lang.c
Subject: Re: Question about Linux/gcc and the signal() function prototype.
Date: Mon, 28 Nov 2022 11:47:29 +0000
Lines: 48
Message-ID: <87lenvuwq6.fsf@doppelsaurus.mobileactivedefense.com>
References: <tlq9hg$fuhb$1@news.xmission.com> <ygazgcftf5r.fsf@akutech.de>
<tlqce3$fuhb$2@news.xmission.com>
<87lenwfuq4.fsf@doppelsaurus.mobileactivedefense.com>
<tlvncc$im4v$1@news.xmission.com> <20221127164105.872@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net sgSHrjacpbJddE1NTY2ksQxcXYGDiCvtqNNMzB+de/vgJBgao=
Cancel-Lock: sha1:jUDOgj9AYpvj7lzkE6UPd9f2kW0= sha1:no8CPthPEWVuxo3xvSGMyXofeeg=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Mon, 28 Nov 2022 11:47 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:
> On 2022-11-27, Kenny McCormack <gazelle@shell.xmission.com> wrote:
>> In article <87lenwfuq4.fsf@doppelsaurus.mobileactivedefense.com>,
>> Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>>gazelle@shell.xmission.com (Kenny McCormack) writes:
>>>
>>>[sighandler_t confusion]
>>>
>>>> All of this seems to be an artifact of the fact that functions and pointers
>>>> to functions are (basically) the same thing. This isn't true for any other
>>>> type of object.
>>>
>>>It's basically the same as with array types: An object which has a function
>>>type is automatically converted to a pointer to a function when used as
>>>argument of something. But they're nevertheless distinct. Stevens uses
>>>
>>>typedef void sighandler(int);
>>>sighandler *signal(int, sighandler *);
>>>
>>>in newer editions of APUE.
>>
>> Yes. That makes more sense.
>>
>> Probably won't ever get fixed, though.
>
> With sighandler defined that way, you can do this:
>
> sighandler myhandler; // forward declaration of your handler
>
> void myhandler(int) // ... but no way of using sighandler for defining
> {
> }
>
> It has little value compared to just making a typedef for the pointer.

This calls the following "famous wast lard" to mind (from the GLib
documentation)

typedef void *gpointer;

Gpointer is the GLib way of declaring a pointer to void. It looks better
than void * and is easier to use.

For people who don't belong to the I-have-to-use-C-but-hate-it!!1
faction, pointers are declared by suffixing a base type with *. Hence,
creating a typedef for the function type and deriving a pointer type
from that by suffixing it with * is consistent with the type system of
the language in general while using typedef to hide the * isn't.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor