Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Inquiry is fatal to certainty." -- Will Durant


devel / comp.lang.c / Effect of CPP tags

SubjectAuthor
* Effect of CPP tagsJanis Papanagnou
+- Re: Effect of CPP tagsLowell Gilbert
+* Re: Effect of CPP tagsKaz Kylheku
|`* Re: Effect of CPP tagsSpiros Bousbouras
| `- Re: Effect of CPP tagsTim Rentsch
+* Re: Effect of CPP tagsJanis Papanagnou
|+* Re: Effect of CPP tagsLowell Gilbert
||+* Re: Effect of CPP tagsKeith Thompson
|||`* Re: Effect of CPP tagsKaz Kylheku
||| `* Re: Effect of CPP tagsKeith Thompson
|||  `* Re: Effect of CPP tagsTim Rentsch
|||   `* Re: Effect of CPP tagsKaz Kylheku
|||    +- Re: Effect of CPP tagsJames Kuyper
|||    +* Re: Effect of CPP tagsJames Kuyper
|||    |`* Re: Effect of CPP tagsKaz Kylheku
|||    | +* Re: Effect of CPP tagsJames Kuyper
|||    | |`- Re: Effect of CPP tagsTim Rentsch
|||    | `* Re: Effect of CPP tagsTim Rentsch
|||    |  `* Re: Effect of CPP tagsKeith Thompson
|||    |   +- Re: Effect of CPP tagsDavid Brown
|||    |   +* Re: Effect of CPP tagsTim Rentsch
|||    |   |`- Re: Effect of CPP tagsKeith Thompson
|||    |   `- Re: Effect of CPP tagsTim Rentsch
|||    `- Re: Effect of CPP tagsTim Rentsch
||+* Re: Effect of CPP tagsKaz Kylheku
|||+- Re: Effect of CPP tagsKaz Kylheku
|||`* Re: Effect of CPP tagsLowell Gilbert
||| `- Re: Effect of CPP tagsJanis Papanagnou
||`* Re: Effect of CPP tagsJanis Papanagnou
|| `- Re: Effect of CPP tagsKaz Kylheku
|+- Re: Effect of CPP tagsKaz Kylheku
|`* Re: Effect of CPP tagsScott Lurndal
| +* Re: Effect of CPP tagsJanis Papanagnou
| |`* Re: Effect of CPP tagsKeith Thompson
| | +* Re: Effect of CPP tagsScott Lurndal
| | |`* Re: Effect of CPP tagsDavid Brown
| | | `* Re: Effect of CPP tagsJames Kuyper
| | |  `- Re: Effect of CPP tagsDavid Brown
| | `- Re: Effect of CPP tagsTim Rentsch
| `- usleep (Was: Effect of CPP tags)Kenny McCormack
+* Re: Effect of CPP tagsLawrence D'Oliveiro
|`* Re: Effect of CPP tagsBart
| +* Re: Effect of CPP tagsDavid Brown
| |`* Re: Effect of CPP tagsKeith Thompson
| | `* Re: Effect of CPP tagsKaz Kylheku
| |  `* Re: Effect of CPP tagsBart
| |   +* Re: Effect of CPP tagsLawrence D'Oliveiro
| |   |`* Re: Effect of CPP tagsBart
| |   | `* Re: Effect of CPP tagsLawrence D'Oliveiro
| |   |  `* Re: Effect of CPP tagsBart
| |   |   +* Re: Effect of CPP tagsScott Lurndal
| |   |   |+* Re: Effect of CPP tagsDavid Brown
| |   |   ||`- Re: Effect of CPP tagsBGB
| |   |   |`* Re: Effect of CPP tagsBart
| |   |   | `- Re: Effect of CPP tagsDavid Brown
| |   |   `- Re: Effect of CPP tagsLawrence D'Oliveiro
| |   `* Re: Effect of CPP tagsDavid Brown
| |    +* Re: Effect of CPP tagsBart
| |    |+- Re: Effect of CPP tagsScott Lurndal
| |    |+* Re: Effect of CPP tagsKaz Kylheku
| |    ||+* Re: Effect of CPP tagsBart
| |    |||`* Re: Effect of CPP tagsBart
| |    ||| +- Re: Effect of CPP tagsKeith Thompson
| |    ||| `* Re: Effect of CPP tagsKaz Kylheku
| |    |||  `* Re: Effect of CPP tagsKeith Thompson
| |    |||   +* Re: Effect of CPP tagsJanis Papanagnou
| |    |||   |`- Re: Effect of CPP tagsKeith Thompson
| |    |||   `- Re: Effect of CPP tagsKaz Kylheku
| |    ||`- Re: Effect of CPP tagsScott Lurndal
| |    |`- Re: Effect of CPP tagsDavid Brown
| |    `* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     +* Re: Effect of CPP tagsChris M. Thomasson
| |     |`* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     | `* Re: Effect of CPP tagsChris M. Thomasson
| |     |  `* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     |   +- Re: Effect of CPP tagsChris M. Thomasson
| |     |   +- Re: Effect of CPP tagsChris M. Thomasson
| |     |   +- Re: Effect of CPP tagsKaz Kylheku
| |     |   `- Re: Effect of CPP tagsBlue-Maned_Hawk
| |     +* Re: Effect of CPP tagsDavid Brown
| |     |+* Re: Effect of CPP tagsBart
| |     ||+* Re: Effect of CPP tagsDavid Brown
| |     |||+- Re: Effect of CPP tagsBlue-Maned_Hawk
| |     |||`* Re: Effect of CPP tagsBart
| |     ||| `* Re: Effect of CPP tagsDavid Brown
| |     |||  `* Re: Effect of CPP tagsBart
| |     |||   +* Re: Effect of CPP tagsChris M. Thomasson
| |     |||   |`- Re: Effect of CPP tagsChris M. Thomasson
| |     |||   +* Re: Effect of CPP tagstTh
| |     |||   |+- Re: Effect of CPP tagsLawrence D'Oliveiro
| |     |||   |+- Re: Effect of CPP tagsKaz Kylheku
| |     |||   |`* Re: Effect of CPP tagsBart
| |     |||   | `* Re: Effect of CPP tagsScott Lurndal
| |     |||   |  `* Re: Effect of CPP tagsBart
| |     |||   |   `* Re: Effect of CPP tagsDavid Brown
| |     |||   |    +* Re: Effect of CPP tagsKaz Kylheku
| |     |||   |    |`* Re: Effect of CPP tagsDavid Brown
| |     |||   |    | `- Re: Effect of CPP tagsKaz Kylheku
| |     |||   |    `* Re: Effect of CPP tagsBart
| |     |||   |     +* Re: Effect of CPP tagsScott Lurndal
| |     |||   |     |`* Re: Effect of CPP tagsBart
| |     |||   |     `* Re: Effect of CPP tagsDavid Brown
| |     |||   `* Re: Effect of CPP tagsDavid Brown
| |     ||`* Re: Effect of CPP tagsBlue-Maned_Hawk
| |     |`* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     `* Re: Effect of CPP tagsKaz Kylheku
| +- Re: Effect of CPP tagsRichard Damon
| +* Re: Effect of CPP tagsKaz Kylheku
| +* Re: Effect of CPP tagsBlue-Maned_Hawk
| `- Re: Effect of CPP tagsLawrence D'Oliveiro
`* Re: Effect of CPP tagsTim Rentsch

Pages:123456789101112131415161718192021222324252627
Effect of CPP tags

<umet9d$3hir9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30406&group=comp.lang.c#30406

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Effect of CPP tags
Date: Tue, 26 Dec 2023 16:59:40 +0100
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <umet9d$3hir9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Dec 2023 15:59:41 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0d2367935904de2fe2f82925b52e3e60";
logging-data="3722089"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bh0hVzH1eUe/UR4iA8Y/R"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:touwe/x6htm7TbCeM6FLc8KZoa4=
X-Enigmail-Draft-Status: N1110
X-Mozilla-News-Host: news://news.eternal-september.org:119
 by: Janis Papanagnou - Tue, 26 Dec 2023 15:59 UTC

This is a CPP question that arose last month. It's not about an actual
issue with the software, just out of curiosity and to be sure it works
reliable (it seemingly does).

In a C99 program on Linux (Ubuntu) I intended to use usleep() and then
also strnlen().

When I added usleep() and its include file I got an error and was asked
to define the CPP tag '_BSD_SOURCE'. I did so, and because I wanted
side effects of that tag kept as small as possible I prepended it just
before the respective #include and put it at the end of my #include list

....other #includes...
#define _BSD_SOURCE
#include <unistd.h>

But as got obvious *that* way there had been side-effects and I had to
put the tag at the beginning of all include files (which astonished me)

#define _BSD_SOURCE
#include <unistd.h>
....other #includes here...

For the strnlen() function I needed another CPP tag, '_GNU_SOURCE'. So
now I have both CPP tag definitions before the includes

#define _GNU_SOURCE /* necessary for strnlen() in string.h */
#define _BSD_SOURCE /* necessary for usleep() in unistd.h */
....all #includes here...

The compile showed no error messages and the code works fine (it seems).

Now I'm not feeling very comfortable with that; I seem to declare two
different "philosophies" that way, GNU and BSD. And both tags affect
all include files. - Is that okay?

Last time I looked into the system header files, three decades ago, I
got repelled by all the #ifdef's, cascaded and nested, a spaghetti code
of dependencies; I'm astonished it works. - And the responsibility to
keep all the CPP tags consistent with _all_ the header files lies at
the side of the system headers' developers? The programmer doesn't need
to care?

Janis

Re: Effect of CPP tags

<44edf8lh1n.fsf@be-well.ilk.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30407&group=comp.lang.c#30407

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lguse...@be-well.ilk.org (Lowell Gilbert)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Tue, 26 Dec 2023 17:45:08 -0500
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <44edf8lh1n.fsf@be-well.ilk.org>
References: <umet9d$3hir9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="d1d3edb9a343cabdd359c013a72017cb";
logging-data="3824627"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191ZsADuhSsQWh2jZ701S7G"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:lotjVDJz8dKJB4dn/G0MS8OAR0g=
sha1:8R8TbQa/5X/LtmAUHHFJCFqSyEk=
 by: Lowell Gilbert - Tue, 26 Dec 2023 22:45 UTC

Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

> In a C99 program on Linux (Ubuntu) I intended to use usleep() and then
> also strnlen().

usleep() isn't in C99. It comes from POSIX, where it was declared
obsolete in 2001. [This information is available in "man usleep".]

I don't want to get into checking which version of glibc you're using,
and such details, so in this case I'll just recommend that you follow
POSIX and use nanosleep() instead. You'll need to multiply by a thousand
and reference different include files, but I strongly suspect you can
figure that all out on your own.

With only fabulously rare exceptions (which mostly involve the
programmer knowing more about the implementation of libc than the libc
implementors did), user code should not be defining (or undefining)
_GNU_SOURCE or _BSD_SOURCE. You seem to have had thoughts in that
direction, and you were absolutely right.

Be well.
--
Lowell Gilbert, embedded/networking software engineer
http://be-well.ilk.org/~lowell/

Re: Effect of CPP tags

<20231226143131.916@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30408&group=comp.lang.c#30408

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Tue, 26 Dec 2023 22:50:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 95
Message-ID: <20231226143131.916@kylheku.com>
References: <umet9d$3hir9$1@dont-email.me>
Injection-Date: Tue, 26 Dec 2023 22:50:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4ed03db719374b13a72cfc71b24465a9";
logging-data="3825832"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19V0LXXDkBDWjdHtAFfw++jugwpvPf1Bi4="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:hO3UpVub3bhYl2cDAjy6ry1h5QI=
 by: Kaz Kylheku - Tue, 26 Dec 2023 22:50 UTC

On 2023-12-26, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> This is a CPP question that arose last month. It's not about an actual
> issue with the software, just out of curiosity and to be sure it works
> reliable (it seemingly does).
>
> In a C99 program on Linux (Ubuntu) I intended to use usleep() and then
> also strnlen().
>
> When I added usleep() and its include file I got an error and was asked
> to define the CPP tag '_BSD_SOURCE'. I did so, and because I wanted
> side effects of that tag kept as small as possible I prepended it just
> before the respective #include and put it at the end of my #include list
>
> ...other #includes...
> #define _BSD_SOURCE
> #include <unistd.h>
>
> But as got obvious *that* way there had been side-effects and I had to
> put the tag at the beginning of all include files (which astonished me)

Feature selection macros must be in effect before any system header
is included, and are usually put on the compiler command line:

cc ... -D_BSD_SOURCE -D_XOPEN_SOURCE=700 ...

The concept of feature selection macros is documented in POSIX.

https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap02.html

I will give you an excellent reason not to put them in source code:
their behavior is system-specific. No single combination of these things
works everywhere. It's best to wrestle that out in the configure
scripts and Makefiles, keeping the code clean.

The header files in BSD Unixes make the wrong interpretation of how
feature selection macros are supposed to work. This affects everything
that is based on BSD or has copy and pasted C libraries from BSD:
Android's Bionic, Cygwin's Newlib, Apple's Darwin environment.

The BSD interpretation of feature selection macros is this:

1. All available identifiers are turned on by default.

2. Feature selection macros *restrict* (subtract) from that set.

3. So do macros coming from the compiler's dialect selection.

Under BSD, if you use, say gcc -ansi -D_POSIX_SOURCE, it will
stupidly produce the intersection of pure ANSI and POSIX.
What you wanted was to use the ANSI C dialect of the language, with
POSIX functions. The BSD interpretation is that ANSI means you don't
want <stdio.h> to give you the declaration of fileno or fdopen,
and so the -D_POSIX_SOURCE won't reveal POSIX things in ANSI/ISO C
headers.

Similarly, if you picked _POSIX_SOURCE and _BSD_SOURCE, you would
stupidly get the intersection of those two, not the union.

In other systems, like GNU/Linuxes, Solaris (I think), you get
the union: -ansi -D_POSIX_SOURCE -D_BSD_SOURCE would work as you
expect: your code is the ANSI dialect, and you want header files
to reveal POSIXisms as well as BSD-isms.

In the Apple environment, forget about it; fine-grained feature
selection is broken: you use -D_DARWIN_C_SOURCE and be done with it.
It's like the old -D_HPUX_SOURCE to get anything compiled on HP-UX.

> #define _GNU_SOURCE /* necessary for strnlen() in string.h */

I think once you define _GNU_SOURCE, Glibc's feature selection will
give you everything. BSD functions in the GNU C library are also
considered GNU extensions over POSIX. It's like the GNU equivalent of
_DARWIN_C_SOURCE or _HPUX_SOURCE; you're asking to reveal everything
from the GNU vendor.

On Glibc, the header /usr/include/features.h is the switch where
the feature selection public macros get converted into combinations of
internal private macros which are then used throughout the headers
to turn things on and off. The features.h header contains a
block comment which lists the public feature selection macros, and
another one that describes the internal ones you're not supposed
to use directly.

You can see that for _GNU_SOURCE, the comment says:

_GNU_SOURCE All of the above, plus GNU extensions.

All of the above refers to all the POSIX, X/Open, BSD stuff
listed above that.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Effect of CPP tags

<ib2w1CqX8rwIzAb9V@bongo-ra.co>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30409&group=comp.lang.c#30409

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Wed, 27 Dec 2023 17:11:45 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <ib2w1CqX8rwIzAb9V@bongo-ra.co>
References: <umet9d$3hir9$1@dont-email.me> <20231226143131.916@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Dec 2023 17:11:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9010053ac3a73bb20b917c86676d4218";
logging-data="6122"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mil567FKmwA/iVFfMAVIV"
Cancel-Lock: sha1:MkE7CmxYRFQ9C/PCXKfrgF8hAGs=
X-Server-Commands: nowebcancel
X-Organisation: Weyland-Yutani
In-Reply-To: <20231226143131.916@kylheku.com>
 by: Spiros Bousbouras - Wed, 27 Dec 2023 17:11 UTC

On Tue, 26 Dec 2023 22:50:40 -0000 (UTC)
Kaz Kylheku <433-929-6894@kylheku.com> wrote:
> On 2023-12-26, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> > This is a CPP question that arose last month. It's not about an actual
> > issue with the software, just out of curiosity and to be sure it works
> > reliable (it seemingly does).
> >
> > In a C99 program on Linux (Ubuntu) I intended to use usleep() and then
> > also strnlen().
> >
> > When I added usleep() and its include file I got an error and was asked
> > to define the CPP tag '_BSD_SOURCE'. I did so, and because I wanted
> > side effects of that tag kept as small as possible I prepended it just
> > before the respective #include and put it at the end of my #include list
> >
> > ...other #includes...
> > #define _BSD_SOURCE
> > #include <unistd.h>
> >
> > But as got obvious *that* way there had been side-effects and I had to
> > put the tag at the beginning of all include files (which astonished me)
>
> Feature selection macros must be in effect before any system header
> is included, and are usually put on the compiler command line:
>
> cc ... -D_BSD_SOURCE -D_XOPEN_SOURCE=700 ...
>
> The concept of feature selection macros is documented in POSIX.
>
> https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap02.html

On Linux there exists also man page feature_test_macros which says : "In
order to be effective, a feature test macro must be defined before including
any header files."

By the way , this kind of question is more appropriate for
comp.unix.programmer .

Re: Effect of CPP tags

<umk836$ehn5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30416&group=comp.lang.c#30416

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 28 Dec 2023 17:34:45 +0100
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <umk836$ehn5$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 28 Dec 2023 16:34:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cb6050195e1fb42308e82c985667a1d1";
logging-data="476901"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fF6LbrQBiqRhlauuxxwf7"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:N5Lym4QSvC20WJIMfCrRs82lLRk=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <umet9d$3hir9$1@dont-email.me>
 by: Janis Papanagnou - Thu, 28 Dec 2023 16:34 UTC

On 26.12.2023 16:59, Janis Papanagnou wrote:
> [...]
> In a C99 program on Linux (Ubuntu) I intended to use usleep() and then
> also strnlen().
>
> When I added usleep() and its include file I got an error and was asked
> to define the CPP tag '_BSD_SOURCE'. [...]

Thanks for all the replies.

Kaz wrote:
>> Feature selection macros must be in effect before any system header
>> is included, and are usually put on the compiler command line:

Right. This time I came from the functions' man pages and read that
such tags are necessary for them, so I didn't think about the original
purpose of these tags. I forgot that decades ago we used for platform
specific declarations. Thanks for refreshing my neurons.

>> I think once you define _GNU_SOURCE, Glibc's feature selection will
>> give you everything.

Indeed. I removed the one obsolete tag.

Lowell wrote:
>> usleep() isn't in C99. It comes from POSIX, where it was declared
>> obsolete in 2001.

Yes, I read about that. Though here I'm just programming non-portably
for my local (and static, non-changing) environment, so it's not an
issue in practice. Generally I try to program close to standards (but
standards obviously also change, as we see).

>> I'll just recommend that you follow POSIX and use nanosleep()
>> instead.

When I had read about the various 'sleep' options I decided to use one
which supports sub-second resolution and with a most simple interface.
That's why my choice was the simple 'usleep(usec);' even if obsolete
by POSIX. The nanosleep() is not "very complex", sure, but I'd have to
litter my code with variables unnecessary in my context, and also the
advertised "advantages" of this function do not apply in my case.[*]

And thanks for your confirmation that my "thoughts" about "not looking
right to use _GNU_SOURCE and _BSD_SOURCE" was not unjustified.

Spiros wrote:
>> By the way , this kind of question is more appropriate for
>> comp.unix.programmer

I was indeed pondering about that. But I'm not programming Unix, and
here I came from an application programming question so my choice was
this newsgroup, and I think (and hope) it has not been a bad choice.

I certainly found the experts to get the clarifications, suggestions,
and insights that were helpful.

Janis

[*] To illustrate: I recall a similar decision in Java context. There
was a simple and easy to use rexexp library (from Apache, IIRC). And
there was also a most flexible blown up library that made its usage a
lot more bulky (using and instantiating many classes and dependencies).
I used the simple, user-friendly one. Later the bulky library became
the Java standard.

Re: Effect of CPP tags

<4434vmp2fl.fsf@be-well.ilk.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30417&group=comp.lang.c#30417

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lguse...@be-well.ilk.org (Lowell Gilbert)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 28 Dec 2023 14:11:42 -0500
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <4434vmp2fl.fsf@be-well.ilk.org>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="3eec9e74f7d159af8ce08156d5a8e07a";
logging-data="521244"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Rth63TtrlkuGvZ+mdWtzM"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:MNSxrWnA05fAg3nv/5YQFeZAWXM=
sha1:jRNac46sCcF4OwELm+DFdT2JIMY=
 by: Lowell Gilbert - Thu, 28 Dec 2023 19:11 UTC

Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

> Lowell wrote:
>>> I'll just recommend that you follow POSIX and use nanosleep()
>>> instead.
>
> When I had read about the various 'sleep' options I decided to use one
> which supports sub-second resolution and with a most simple interface.
> That's why my choice was the simple 'usleep(usec);' even if obsolete
> by POSIX. The nanosleep() is not "very complex", sure, but I'd have to
> litter my code with variables unnecessary in my context, and also the
> advertised "advantages" of this function do not apply in my case.[*]

To be honest,I didn't actually understand where your problem came from
in the first place -- I just chose not to bring up more than one point
at a time. While usleep() is obsolete, it works fine, without any
feature test macro games, on (as far as I know) all POSIX-ish
systems. Certainly on recent Ubuntu, the following program compiles and
runs perfectly well without even any warnings with even the most extreme
levels of warning enabled:

#include <stdio.h>
#include <unistd.h>

int main(void)
{ printf("starting\n");
usleep(2500000);
printf("finishing\n");
}

--
Lowell Gilbert, embedded/networking software engineer
http://be-well.ilk.org/~lowell/

Re: Effect of CPP tags

<87wmsyuj1l.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30418&group=comp.lang.c#30418

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 28 Dec 2023 13:13:58 -0800
Organization: None to speak of
Lines: 34
Message-ID: <87wmsyuj1l.fsf@nosuchdomain.example.com>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
<4434vmp2fl.fsf@be-well.ilk.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="06940e18ca52db0617e0b1c6aadcfa47";
logging-data="558007"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oN2KnbXuSZBRPww8AZFMt"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:lraVM9ISS4Cp8TS43bhTV6wbtEo=
sha1:j2e+sKqAMJU9iPbo2kxukqA/Wso=
 by: Keith Thompson - Thu, 28 Dec 2023 21:13 UTC

Lowell Gilbert <lgusenet@be-well.ilk.org> writes:
[...]
> To be honest,I didn't actually understand where your problem came from
> in the first place -- I just chose not to bring up more than one point
> at a time. While usleep() is obsolete, it works fine, without any
> feature test macro games, on (as far as I know) all POSIX-ish
> systems. Certainly on recent Ubuntu, the following program compiles and
> runs perfectly well without even any warnings with even the most extreme
> levels of warning enabled:
>
> #include <stdio.h>
> #include <unistd.h>
>
> int main(void)
> {
> printf("starting\n");
> usleep(2500000);
> printf("finishing\n");
> }

I think the warnings you enabled weren't extreme enough:

$ gcc -std=c11 -c c.c
c.c: In function ‘main’:
c.c:7:4: warning: implicit declaration of function ‘usleep’; did you mean ‘sleep’? [-Wimplicit-function-declaration]
7 | usleep(2500000);
| ^~~~~~
| sleep
$

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: Effect of CPP tags

<20231228131349.189@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30419&group=comp.lang.c#30419

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 28 Dec 2023 21:22:42 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 75
Message-ID: <20231228131349.189@kylheku.com>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
Injection-Date: Thu, 28 Dec 2023 21:22:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a83eb1c745b020314dcfd8bc886c80da";
logging-data="559866"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ebVe6Z7UY9LaAd2zUewuLjARRlYhIsow="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:3bjt0HITRcZTbZkIqRXL2Ln6Prc=
 by: Kaz Kylheku - Thu, 28 Dec 2023 21:22 UTC

On 2023-12-28, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> On 26.12.2023 16:59, Janis Papanagnou wrote:
>> [...]
>> In a C99 program on Linux (Ubuntu) I intended to use usleep() and then
>> also strnlen().
>>
>> When I added usleep() and its include file I got an error and was asked
>> to define the CPP tag '_BSD_SOURCE'. [...]
>
> Thanks for all the replies.
>
>
> Kaz wrote:
>>> Feature selection macros must be in effect before any system header
>>> is included, and are usually put on the compiler command line:
>
> Right. This time I came from the functions' man pages and read that
> such tags are necessary for them, so I didn't think about the original
> purpose of these tags. I forgot that decades ago we used for platform
> specific declarations. Thanks for refreshing my neurons.

I'm a real stickler for not wanting to reveal everything in the headers,
if possible.

So here is the irony. On BSD libraries, you can get BSD symbols with
a dialect option like -ansi or -std=C99 fi you use the secret, internal,
double-leading-underscored feature selector __BSD_VISIBLE. As in:

gcc ... -std=c99 -D__BSD_VISIBLE

The -std=c99 generates certain #defines with BSD takes as a clue to
hide everything not related to C99 from every standard ISO C header.

We then pry that open with __BSD_VISIBLE. If we used -D_BSD_SOURCE,
that wouldn't work.

In the TXR configure script, I have an elaborate test.
(Not shown is the conftest function which compiles conftest.c,
with the assistance of a rule in the Makefile, and reports success):

printf "Detecting what symbol reveals BSD functions ... "

cat > conftest.c <<!
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char **argv)
{ int (*pdaemon)(int, int) = &daemon;
} !

if conftest ; then
printf "none needed\n"
else
for flag in _DEFAULT_SOURCE _BSD_SOURCE __BSD_VISIBLE _GNU_SOURCE _X_OOPS; do
if [ $flag = _X_OOPS ] ; then
printf "failed\n"
break
fi

if conftest EXTRA_FLAGS=-D$flag ; then
printf "%s\n" $flag
lang_flags="$lang_flags -D$flag"
gen_config_make
break
fi
done
fi

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Effect of CPP tags

<20231228132332.148@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30420&group=comp.lang.c#30420

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 28 Dec 2023 21:33:33 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 82
Message-ID: <20231228132332.148@kylheku.com>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
<4434vmp2fl.fsf@be-well.ilk.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Dec 2023 21:33:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a83eb1c745b020314dcfd8bc886c80da";
logging-data="564924"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/u/aSiE69B71Brxn7/Gv910cjwHaq94Qs="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:VXtoLF8UfOKivoTSLefragirHtM=
 by: Kaz Kylheku - Thu, 28 Dec 2023 21:33 UTC

On 2023-12-28, Lowell Gilbert <lgusenet@be-well.ilk.org> wrote:
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
>
>> Lowell wrote:
>>>> I'll just recommend that you follow POSIX and use nanosleep()
>>>> instead.
>>
>> When I had read about the various 'sleep' options I decided to use one
>> which supports sub-second resolution and with a most simple interface.
>> That's why my choice was the simple 'usleep(usec);' even if obsolete
>> by POSIX. The nanosleep() is not "very complex", sure, but I'd have to
>> litter my code with variables unnecessary in my context, and also the
>> advertised "advantages" of this function do not apply in my case.[*]
>
> To be honest,I didn't actually understand where your problem came from
> in the first place -- I just chose not to bring up more than one point
> at a time. While usleep() is obsolete, it works fine, without any
> feature test macro games, on (as far as I know) all POSIX-ish
> systems. Certainly on recent Ubuntu, the following program compiles and
> runs perfectly well without even any warnings with even the most extreme
> levels of warning enabled:
>
> #include <stdio.h>
> #include <unistd.h>
>
> int main(void)
> {
> printf("starting\n");
> usleep(2500000);
> printf("finishing\n");
> }

But if you don't specify any options, you're not even specifying the C
dialect. You will get whatever dialect your gcc installation defaults
to. That is always a GNU dialect, firstly, which you might not want.
Secondly, it's a moving target; it' used to be gnu89, then gnu99
then gnu11. Now GCC defaults to gnu17.

Once you specify the dialect, things get strict.

$ gcc usleep.c

Nothing

$ gcc -std=c99 usleep.c
usleep.c: In function ‘main’:
usleep.c:7:4: warning: implicit declaration of function ‘usleep’; did
you mean ‘sleep’? [-Wimplicit-function-declaration]
usleep(2500000);
^~~~~~
sleep

Oops! Once we use any feature selection macro (or compiler option that
generates #defines that serve as feature selection macros) the set of
what is visible is reduced to some minimal set, and from then, the
feature macros turn on the selected symbols.

Thus <unistd.h> reveals only some fairly old POSIX functions.
Maybe not even up to 2003? The details depend on the behavior of the C
library, like Glibc's <features.h>.

The GNU-documented preferred way to coax usleep out of <unistd.h>
under this condition is this:

$ gcc -std=c99 -D_DEFAULT_SOURCE usleep.c

The _DEFAULT_SOURCE feature selection symbol brings out some traditional
functions (or something like that) without bringing in all the full
blown extensions of _GNU_SOURCE.

The BSD people misunderstood this whole thing. Without feature
selections, they reveal everything. But the semantics of a feature
selection is "hide everything except this". They neglected to implement
the correct logic: "if at least one feature selection is present, hide
everything except for some minimal base, and then for every feature
selection, make those respective symbols visible."

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Effect of CPP tags

<20231228133553.230@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30421&group=comp.lang.c#30421

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 28 Dec 2023 21:42:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <20231228133553.230@kylheku.com>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
<4434vmp2fl.fsf@be-well.ilk.org> <20231228132332.148@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Dec 2023 21:42:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a83eb1c745b020314dcfd8bc886c80da";
logging-data="564924"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180a9kmkkLHEzAHWYFr5VVOTj05dmsy5Zw="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:7lE5b8P+I5Aqxt7CUFzcZooQS7M=
 by: Kaz Kylheku - Thu, 28 Dec 2023 21:42 UTC

On 2023-12-28, Kaz Kylheku <433-929-6894@kylheku.com> wrote:
> Once you specify the dialect, things get strict.
>
> $ gcc usleep.c
>
> Nothing
>
> $ gcc -std=c99 usleep.c
> usleep.c: In function ‘main’:
> usleep.c:7:4: warning: implicit declaration of function ‘usleep’; did
> you mean ‘sleep’? [-Wimplicit-function-declaration]
> usleep(2500000);
> ^~~~~~
> sleep

For completeness:

No warning with -Wall without a dialect selection: declaration of usleep
is not hidden in <unistd.h>:

$ gcc -Wall usleep.c

No warning with C89. But that's because GCC doesn't warn about implicit
declarations when in C89 mode:

$ gcc -std=c89 usleep.c

Put in -Wall and we see that usleep is hidden in <unistd.h>

$ gcc -std=c89 -Wall usleep.c
usleep.c: In function ‘main’:
usleep.c:7:4: warning: implicit declaration of function ‘usleep’

Re: Effect of CPP tags

<20231228134234.49@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30422&group=comp.lang.c#30422

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 28 Dec 2023 21:47:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <20231228134234.49@kylheku.com>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
<4434vmp2fl.fsf@be-well.ilk.org> <87wmsyuj1l.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Dec 2023 21:47:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a83eb1c745b020314dcfd8bc886c80da";
logging-data="567171"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19SuHjxRkSRZqTJDgEY8phUC93e7/oxev4="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:dzYzXaOalFnSRlJ9P/u0VZw4hF4=
 by: Kaz Kylheku - Thu, 28 Dec 2023 21:47 UTC

On 2023-12-28, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Lowell Gilbert <lgusenet@be-well.ilk.org> writes:
> [...]
>> To be honest,I didn't actually understand where your problem came from
>> in the first place -- I just chose not to bring up more than one point
>> at a time. While usleep() is obsolete, it works fine, without any
>> feature test macro games, on (as far as I know) all POSIX-ish
>> systems. Certainly on recent Ubuntu, the following program compiles and
>> runs perfectly well without even any warnings with even the most extreme
>> levels of warning enabled:
>>
>> #include <stdio.h>
>> #include <unistd.h>
>>
>> int main(void)
>> {
>> printf("starting\n");
>> usleep(2500000);
>> printf("finishing\n");
>> }
>
> I think the warnings you enabled weren't extreme enough:
>
> $ gcc -std=c11 -c c.c
> c.c: In function ‘main’:
> c.c:7:4: warning: implicit declaration of function ‘usleep’; did you mean ‘sleep’? [-Wimplicit-function-declaration]
> 7 | usleep(2500000);
> | ^~~~~~
> | sleep
> $

What's actually happening is that -std=c11 causes <unistd.h> to hide
the usleep declaration. (Even tough <unistd.h> isn't in ISO C).

If you just use:

gcc -Wimplicit-function-declaration -c c.c

it will not warn. Since no feature selection has been made, all symbols
in headers are maximally visible.

Unless you're using an old GCC whose default dialect is gnu89,
the -Wimplicit-functiond-declaration option is already present in
the default dialect (like gnu99, gnu11 or gnu17).

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Effect of CPP tags

<44v88i7wtl.fsf@be-well.ilk.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30423&group=comp.lang.c#30423

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lguse...@be-well.ilk.org (Lowell Gilbert)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 28 Dec 2023 18:04:54 -0500
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <44v88i7wtl.fsf@be-well.ilk.org>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
<4434vmp2fl.fsf@be-well.ilk.org> <20231228132332.148@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="c6b9824a6de4fc3f3c9c5c602906a261";
logging-data="587380"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/CDLrxMlFg5f3knSl8+9nf"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:dY+YlKD7HbGC3u8r8+0F5EmWnws=
sha1:y0syjEQQ3eK2Nxb/eO6W5J8v47U=
 by: Lowell Gilbert - Thu, 28 Dec 2023 23:04 UTC

Kaz Kylheku <433-929-6894@kylheku.com> writes:

> On 2023-12-28, Lowell Gilbert <lgusenet@be-well.ilk.org> wrote:
>> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
>>
>>> Lowell wrote:
>>>>> I'll just recommend that you follow POSIX and use nanosleep()
>>>>> instead.
>>>
>>> When I had read about the various 'sleep' options I decided to use one
>>> which supports sub-second resolution and with a most simple interface.
>>> That's why my choice was the simple 'usleep(usec);' even if obsolete
>>> by POSIX. The nanosleep() is not "very complex", sure, but I'd have to
>>> litter my code with variables unnecessary in my context, and also the
>>> advertised "advantages" of this function do not apply in my case.[*]
>>
>> To be honest,I didn't actually understand where your problem came from
>> in the first place -- I just chose not to bring up more than one point
>> at a time. While usleep() is obsolete, it works fine, without any
>> feature test macro games, on (as far as I know) all POSIX-ish
>> systems. Certainly on recent Ubuntu, the following program compiles and
>> runs perfectly well without even any warnings with even the most extreme
>> levels of warning enabled:
>>
>> #include <stdio.h>
>> #include <unistd.h>
>>
>> int main(void)
>> {
>> printf("starting\n");
>> usleep(2500000);
>> printf("finishing\n");
>> }
>
> But if you don't specify any options, you're not even specifying the C
> dialect. You will get whatever dialect your gcc installation defaults
> to. That is always a GNU dialect, firstly, which you might not want.
> Secondly, it's a moving target; it' used to be gnu89, then gnu99
> then gnu11. Now GCC defaults to gnu17.
>
> Once you specify the dialect, things get strict.

Yes, that's true. I was making an educated guess that the original poster
wasn't actually asking for strict C99, despite referring to a "C99 program." I
think the statement that "I'm just programming non-portably for my local (and
static, non-changing) environment" is strong evidence for this. The discussion
had clearly gone beyond standard C before that, usleep() has never been part
of the actual language.

Be well.
--
Lowell Gilbert, embedded/networking software engineer
http://be-well.ilk.org/~lowell/

Re: Effect of CPP tags

<87sf3lvs43.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30424&group=comp.lang.c#30424

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 28 Dec 2023 15:12:44 -0800
Organization: None to speak of
Lines: 58
Message-ID: <87sf3lvs43.fsf@nosuchdomain.example.com>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
<4434vmp2fl.fsf@be-well.ilk.org>
<87wmsyuj1l.fsf@nosuchdomain.example.com>
<20231228134234.49@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="429276411a044e69398eca77c4a97f98";
logging-data="586981"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX181kjLGKg3hhOmj4lq78s/k"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:3v6RyUFrZDdeFjhwgKDgrJhJfII=
sha1:lkspf3XnsgPfeyRyH7u40/UPtbk=
 by: Keith Thompson - Thu, 28 Dec 2023 23:12 UTC

Kaz Kylheku <433-929-6894@kylheku.com> writes:
> On 2023-12-28, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>> Lowell Gilbert <lgusenet@be-well.ilk.org> writes:
>> [...]
>>> To be honest,I didn't actually understand where your problem came from
>>> in the first place -- I just chose not to bring up more than one point
>>> at a time. While usleep() is obsolete, it works fine, without any
>>> feature test macro games, on (as far as I know) all POSIX-ish
>>> systems. Certainly on recent Ubuntu, the following program compiles and
>>> runs perfectly well without even any warnings with even the most extreme
>>> levels of warning enabled:
>>>
>>> #include <stdio.h>
>>> #include <unistd.h>
>>>
>>> int main(void)
>>> {
>>> printf("starting\n");
>>> usleep(2500000);
>>> printf("finishing\n");
>>> }
>>
>> I think the warnings you enabled weren't extreme enough:
>>
>> $ gcc -std=c11 -c c.c
>> c.c: In function ‘main’:
>> c.c:7:4: warning: implicit declaration of function ‘usleep’; did you mean ‘sleep’? [-Wimplicit-function-declaration]
>> 7 | usleep(2500000);
>> | ^~~~~~
>> | sleep
>> $
>
> What's actually happening is that -std=c11 causes <unistd.h> to hide
> the usleep declaration. (Even tough <unistd.h> isn't in ISO C).

That's an interesting choice. Just including <unistd.h> has undefined
behavior as far as ISO C is concerned, but gcc never (?) warns about
that regardless of the options.

In glibc on Ubuntu 22.04, the declaration of usleep() in <unistd.h>
is protected by:

#if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
|| defined __USE_MISC

IMHO it would have been better if standards that extend the C library
declared all additional declarations in non-standard headers like
<unistd.h> rather than adding them to ISO C standard headers like
<stdio.h> and <stdlib.h>. But a lot of the stuff that POSIX adds
probably predates ISO C90, so there was never a good opportunity to make
a clean split.

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: Effect of CPP tags

<umlba2$iq0h$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30425&group=comp.lang.c#30425

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 29 Dec 2023 02:35:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <umlba2$iq0h$3@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Dec 2023 02:35:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d90672d7f8b83ec7c390dfb9e1c069cf";
logging-data="616465"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+76FdvKOPPwRvR9n/Bp3az"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:wdj/8lLDAtoMf0O249f020KQMhs=
 by: Lawrence D'Oliv - Fri, 29 Dec 2023 02:35 UTC

On Tue, 26 Dec 2023 16:59:40 +0100, Janis Papanagnou wrote:

> But as got obvious *that* way there had been side-effects and I had to
> put the tag at the beginning of all include files (which astonished me)

It has always been thus
<https://manpages.debian.org/7/feature_test_macros.en.html>:

NOTE: In order to be effective, a feature test macro must be defined
before including any header files.

> Last time I looked into the system header files, three decades ago, I
> got repelled by all the #ifdef's, cascaded and nested, a spaghetti code
> of dependencies; I'm astonished it works.

The whole concept of include files and string-based macro processing is
flawed. But that’s C for you ...

Re: Effect of CPP tags

<ummhnp$rf7k$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30430&group=comp.lang.c#30430

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.cm (Bart)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 29 Dec 2023 13:31:37 +0000
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <ummhnp$rf7k$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Dec 2023 13:31:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="22e6bd9e86e7086d3fedf9619db737b8";
logging-data="900340"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ckLoeAsbg96CbzRjTANgbcmVpp9ElZP0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:JsG8orpXJLBFwqhDmfg9tYgKrRQ=
In-Reply-To: <umlba2$iq0h$3@dont-email.me>
Content-Language: en-GB
 by: Bart - Fri, 29 Dec 2023 13:31 UTC

On 29/12/2023 02:35, Lawrence D'Oliveiro wrote:
> On Tue, 26 Dec 2023 16:59:40 +0100, Janis Papanagnou wrote:
>
>> But as got obvious *that* way there had been side-effects and I had to
>> put the tag at the beginning of all include files (which astonished me)
>
> It has always been thus
> <https://manpages.debian.org/7/feature_test_macros.en.html>:
>
> NOTE: In order to be effective, a feature test macro must be defined
> before including any header files.
>
>> Last time I looked into the system header files, three decades ago, I
>> got repelled by all the #ifdef's, cascaded and nested, a spaghetti code
>> of dependencies; I'm astonished it works.
>
> The whole concept of include files and string-based macro processing is
> flawed. But that’s C for you ...

It's not just C's fault. It's the insistence of having have just ONE
system header that has to work for as many platforms and versions as
possible.

Then that is just added to over the years to include to result in the
patched-together mess that you see that is utterly unreadable. You can't
simplify it it take things out because something could break. It is fragile.

Why not have a dedicated header file that is the specific to a
particular version of a C compiler for a given platform? That it can be
streamlined for that purpose.

If someone is maintaining compilers that need to work across a range of
targets, then they can have a process that synthesises the header needed
for a specific configuration.

(I guess this is something that is harder on Linux because there, many
standard headers are not part of a specific C compiler, but are a
resource shared by all C compilers, or tools that need to process C
headers.)

Re: Effect of CPP tags

<ummmqe$s4od$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30431&group=comp.lang.c#30431

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 29 Dec 2023 15:58:22 +0100
Organization: A noiseless patient Spider
Lines: 73
Message-ID: <ummmqe$s4od$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Dec 2023 14:58:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e9539489de686d5d1af102aae405ff52";
logging-data="922381"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Lqe2bOFToW0kVol8hcF2UIznIRbKeKVY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:IvWpOY8Y9M6xinA7THVzKXdtiDY=
Content-Language: en-GB
In-Reply-To: <ummhnp$rf7k$1@dont-email.me>
 by: David Brown - Fri, 29 Dec 2023 14:58 UTC

On 29/12/2023 14:31, Bart wrote:
> On 29/12/2023 02:35, Lawrence D'Oliveiro wrote:
> > On Tue, 26 Dec 2023 16:59:40 +0100, Janis Papanagnou wrote:
> >
> >> But as got obvious *that* way there had been side-effects and I had to
> >> put the tag at the beginning of all include files (which astonished me)
> >
> > It has always been thus
> > <https://manpages.debian.org/7/feature_test_macros.en.html>:
> >
> >      NOTE: In order to be effective, a feature test macro must be
> defined
> >      before including any header files.
> >
> >> Last time I looked into the system header files, three decades ago, I
> >> got repelled by all the #ifdef's, cascaded and nested, a spaghetti code
> >> of dependencies; I'm astonished it works.
> >
> > The whole concept of include files and string-based macro processing is
> > flawed. But that’s C for you ...
>
> It's not just C's fault. It's the insistence of having have just ONE
> system header that has to work for as many platforms and versions as
> possible.
>
> Then that is just added to over the years to include to result in the
> patched-together mess that you see that is utterly unreadable. You can't
> simplify it it take things out because something could break. It is
> fragile.
>
> Why not have a dedicated header file that is the specific to a
> particular version of a C compiler for a given platform? That it can be
> streamlined for that purpose.
>

This kind of dilemma turns up all the time in development. You
regularly have multiple variations of projects or code, where most
things are the same but there are a few important differences scattered
around. If you choose to have separate code bases, you have to
duplicate work for new features or bug fixes. If you choose to combine
them, you risk a mess of compile-time conditionals, or run-time
conditionals that complicate the code and make it less efficient. The
first method is a pain for people maintaining the general code, while
the second method is a pain for people only interested in one variation.
Sometimes it is possible to have a clean separation between common
parts and variant-specific parts, other times that just makes things
even more complicated.

There is no good answer here, and often you are stuck with decisions
that made sense when they were made, but are no longer the best choice
as the project has grown and developed. And yet at no point is it
feasible to throw things out and start again.

I agree it is not just C's fault - it is, I think, inevitable for any
long-lived large project that is used in many ways. And it is always
going to be a pain for some people, no matter what is done.

At least for things like glibc the great majority of people using it for
their development can ignore the mess and read the documentation instead
of looking into the header files. And most of those that /do/ need to
look in the headers, only need to do so occasionally.

A useful tool that someone might like to write for this particular
situation would be a partial C preprocessor, letting you choose what
gets handled. You could choose to expand the code here for, say,
_GNU_SOURCE and _BSD_SOURCE - any use of these in #ifdef's and
conditional compilation would be expanded according to whether you have
defined the symbols or not, leaving an output that is easier to
understand while keeping most of the pre-processor stuff unchanged (so
not affecting #includes, and leaving #define'd macros and constants
untouched and therefore more readable).

Re: Effect of CPP tags

<ummn5e$s6ir$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30432&group=comp.lang.c#30432

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 29 Dec 2023 16:04:13 +0100
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <ummn5e$s6ir$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
<4434vmp2fl.fsf@be-well.ilk.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Dec 2023 15:04:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="38e7579e07007f5d4bfdd254edad60a8";
logging-data="924251"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7KyITNKWMX6JtIKaXBD7a"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:/rVnYOtugTUwcilKKbfZZPl5PvA=
In-Reply-To: <4434vmp2fl.fsf@be-well.ilk.org>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Fri, 29 Dec 2023 15:04 UTC

On 28.12.2023 20:11, Lowell Gilbert wrote:
>
> To be honest,I didn't actually understand where your problem came from
> in the first place -- I just chose not to bring up more than one point
> at a time. While usleep() is obsolete, it works fine, without any
> feature test macro games, on (as far as I know) all POSIX-ish
> systems. Certainly on recent Ubuntu, the following program compiles and
> runs perfectly well without even any warnings with even the most extreme
> levels of warning enabled:
> [snip code]

Here's the output of the compiler call with #define _GNU_SOURCE removed

$ cc -std=c99 -o warn warn.c
warn.c: In function ‘delay_time’:
warn.c:368:3: warning: implicit declaration of function ‘strnlen’
[-Wimplicit-function-declaration]
warn.c: In function ‘main’:
warn.c:579:5: warning: implicit declaration of function ‘usleep’
[-Wimplicit-function-declaration]

It compiles, but if I see warnings I nonetheless try to get rid of them.

$ cc --version
cc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

(It's no "recent Ubuntu", I'm sure.)

Janis

Re: Effect of CPP tags

<ummnjm$s8oa$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30433&group=comp.lang.c#30433

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 29 Dec 2023 16:11:49 +0100
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <ummnjm$s8oa$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
<4434vmp2fl.fsf@be-well.ilk.org> <20231228132332.148@kylheku.com>
<44v88i7wtl.fsf@be-well.ilk.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 29 Dec 2023 15:11:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="38e7579e07007f5d4bfdd254edad60a8";
logging-data="926474"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Fjoi+M/xKgao8HQ882xVX"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:oOEop5Hd0b3uuY9UC+gCfiFmXZ4=
In-Reply-To: <44v88i7wtl.fsf@be-well.ilk.org>
 by: Janis Papanagnou - Fri, 29 Dec 2023 15:11 UTC

On 29.12.2023 00:04, Lowell Gilbert wrote:
>
> Yes, that's true. I was making an educated guess that the original poster
> wasn't actually asking for strict C99, despite referring to a "C99 program."

I switched (from the default cc setting) to -std=c99 since when a
compile run said that my program needs C99 to run. That was the
whole reason for it. And I mentioned it in my post since I thought
it would be relevant context information to answer the question.

Janis

Re: Effect of CPP tags

<iXBjN.109557$p%Mb.36381@fx15.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30434&group=comp.lang.c#30434

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!i2pn.org!paganini.bofh.team!2.eu.feeder.erje.net!feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx15.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Effect of CPP tags
Newsgroups: comp.lang.c
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
Lines: 22
Message-ID: <iXBjN.109557$p%Mb.36381@fx15.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 29 Dec 2023 15:52:46 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 29 Dec 2023 15:52:46 GMT
X-Received-Bytes: 1524
 by: Scott Lurndal - Fri, 29 Dec 2023 15:52 UTC

Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

>>> I'll just recommend that you follow POSIX and use nanosleep()
>>> instead.
>
>When I had read about the various 'sleep' options I decided to use one
>which supports sub-second resolution and with a most simple interface.
>That's why my choice was the simple 'usleep(usec);' even if obsolete
>by POSIX. The nanosleep() is not "very complex", sure, but I'd have to
>litter my code with variables unnecessary in my context, and also the
>advertised "advantages" of this function do not apply in my case.[*]

You can always define your own usleep:

inline int
usleep(useconds_t microseconds)
{ struct timespec ts;
ts.tv_sec = microseconds / (useconds_t)1000000;
ts.tv_nsec = (long)(microseconds % (useconds_t)1000000) * 1000L;
return nanosleep(&ts, NULL);
}

Re: Effect of CPP tags

<umms18$sss0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30435&group=comp.lang.c#30435

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 29 Dec 2023 17:27:20 +0100
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <umms18$sss0$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
<iXBjN.109557$p%Mb.36381@fx15.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 29 Dec 2023 16:27:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9a88f9971171da36d21591f54ad7b25f";
logging-data="947072"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cSjE1O1tAxpzKWmCNMIC5"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:sNAmWjQhdpTkjT/AnR+X2D1AaYs=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <iXBjN.109557$p%Mb.36381@fx15.iad>
 by: Janis Papanagnou - Fri, 29 Dec 2023 16:27 UTC

On 29.12.2023 16:52, Scott Lurndal wrote:
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
>
>>>> I'll just recommend that you follow POSIX and use nanosleep()
>>>> instead.
>>
>> When I had read about the various 'sleep' options I decided to use one
>> which supports sub-second resolution and with a most simple interface.
>> That's why my choice was the simple 'usleep(usec);' even if obsolete
>> by POSIX. The nanosleep() is not "very complex", sure, but I'd have to
>> litter my code with variables unnecessary in my context, and also the
>> advertised "advantages" of this function do not apply in my case.[*]
>
> You can always define your own usleep:

LOL, yes. :-)

I usually want to take what's already there and not re-implement
every function. What I mean is; in my case I use a function call
and that is it.

>
> inline int
> usleep(useconds_t microseconds)
> {
> struct timespec ts;
> ts.tv_sec = microseconds / (useconds_t)1000000;
> ts.tv_nsec = (long)(microseconds % (useconds_t)1000000) * 1000L;
> return nanosleep(&ts, NULL);
> }
>

Lowell Gilbert upthread already suggested to use nanosleep() and
do the multiplications, and he was confident, rightly, that I'm
able to "figure that out". :-)

BTW, is 'inline' meanwhile C standard? (I know that from C++ but
haven't done much C for long now.)

Janis

Re: Effect of CPP tags

<ummtra$1a0q5$13@i2pn2.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30436&group=comp.lang.c#30436

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!.POSTED!not-for-mail
From: rich...@damon-family.org (Richard Damon)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 29 Dec 2023 11:58:18 -0500
Organization: i2pn2 (i2pn.org)
Message-ID: <ummtra$1a0q5$13@i2pn2.org>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Dec 2023 16:58:18 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="1377093"; mail-complaints-to="usenet@i2pn2.org";
posting-account="diqKR1lalukngNWEqoq9/uFtbkm5U+w3w6FQ0yesrXg";
User-Agent: Mozilla Thunderbird
Content-Language: en-US
X-Spam-Checker-Version: SpamAssassin 4.0.0
In-Reply-To: <ummhnp$rf7k$1@dont-email.me>
 by: Richard Damon - Fri, 29 Dec 2023 16:58 UTC

On 12/29/23 8:31 AM, Bart wrote:
> On 29/12/2023 02:35, Lawrence D'Oliveiro wrote:
> > On Tue, 26 Dec 2023 16:59:40 +0100, Janis Papanagnou wrote:
> >
> >> But as got obvious *that* way there had been side-effects and I had to
> >> put the tag at the beginning of all include files (which astonished me)
> >
> > It has always been thus
> > <https://manpages.debian.org/7/feature_test_macros.en.html>:
> >
> >      NOTE: In order to be effective, a feature test macro must be
> defined
> >      before including any header files.
> >
> >> Last time I looked into the system header files, three decades ago, I
> >> got repelled by all the #ifdef's, cascaded and nested, a spaghetti code
> >> of dependencies; I'm astonished it works.
> >
> > The whole concept of include files and string-based macro processing is
> > flawed. But that’s C for you ...
>
> It's not just C's fault. It's the insistence of having have just ONE
> system header that has to work for as many platforms and versions as
> possible.
>
> Then that is just added to over the years to include to result in the
> patched-together mess that you see that is utterly unreadable. You can't
> simplify it it take things out because something could break. It is
> fragile.
>
> Why not have a dedicated header file that is the specific to a
> particular version of a C compiler for a given platform? That it can be
> streamlined for that purpose.
>
> If someone is maintaining compilers that need to work across a range of
> targets, then they can have a process that synthesises the header needed
> for a specific configuration.
>
> (I guess this is something that is harder on Linux because there, many
> standard headers are not part of a specific C compiler, but are a
> resource shared by all C compilers, or tools that need to process C
> headers.)
>
>

And using #if in the headers is one way to "have a process" that
"synthesises the header needed for a specific configuration", without
needing some special code in the compiler, and still makes the header
available to the user for inspection.

I suppose the alternative is a separate include hierarchy for EVERY
combination of configurations, and needing to modify multiple headers to
add/fix features.

Re: Effect of CPP tags

<20231229093047.636@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30437&group=comp.lang.c#30437

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 29 Dec 2023 17:44:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 73
Message-ID: <20231229093047.636@kylheku.com>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Dec 2023 17:44:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="52fd9de859b81d17f176357c065ce2c2";
logging-data="974246"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nZFSAAbrBZwWiJMPQcviog9vlrMmly6E="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:xjUZeWy6zadsnUqaSuhr1PpyGg4=
 by: Kaz Kylheku - Fri, 29 Dec 2023 17:44 UTC

On 2023-12-29, Bart <bc@freeuk.cm> wrote:
> On 29/12/2023 02:35, Lawrence D'Oliveiro wrote:
> > On Tue, 26 Dec 2023 16:59:40 +0100, Janis Papanagnou wrote:
> >
> >> But as got obvious *that* way there had been side-effects and I had to
> >> put the tag at the beginning of all include files (which astonished me)
> >
> > It has always been thus
> > <https://manpages.debian.org/7/feature_test_macros.en.html>:
> >
> > NOTE: In order to be effective, a feature test macro must be defined
> > before including any header files.
> >
> >> Last time I looked into the system header files, three decades ago, I
> >> got repelled by all the #ifdef's, cascaded and nested, a spaghetti code
> >> of dependencies; I'm astonished it works.
> >
> > The whole concept of include files and string-based macro processing is
> > flawed. But that’s C for you ...
>
> It's not just C's fault. It's the insistence of having have just ONE
> system header that has to work for as many platforms and versions as
> possible.

Umm, no; system headers are largely system-specific.
>
> Then that is just added to over the years to include to result in the
> patched-together mess that you see that is utterly unreadable. You can't
> simplify it it take things out because something could break. It is fragile.

The preprocessing selection in system headers is for the different
expectations of programs which target different versions of the system
interfaces.

It is to prevent clashes. If an identifier like usleep is hidden,
it means that the program can use it without triggering a redefinition
or other error.

When you compile with, say, -std=c99 (and no other feature selection)
and include <stdio.h>, that header must not declare fdopen or fileno,
which are POSIX extensions. That matters if your program happens to
use these identifiers: which an ISO C program is entitled to do.

> Why not have a dedicated header file that is the specific to a
> particular version of a C compiler for a given platform? That it can be
> streamlined for that purpose.

That's predominantly the case, other than (obviously) for libraries
that are intended to be widely portable.
>
> If someone is maintaining compilers that need to work across a range of
> targets, then they can have a process that synthesises the header needed
> for a specific configuration.

In fact, I remember from long ago that GCC used to have a script,
as part of its build, that would scan the platform's native headers and
generate sanitized versions for GCC. Not sure if that is the case any
more.

> (I guess this is something that is harder on Linux because there, many
> standard headers are not part of a specific C compiler, but are a
> resource shared by all C compilers, or tools that need to process C
> headers.)

Headers on GNU/Linux systems tend to assume GCC. Clang would not be
usable did it not have GCC compatibility.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Effect of CPP tags

<20231229094508.935@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30438&group=comp.lang.c#30438

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!nntp.comgw.net!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 29 Dec 2023 17:51:13 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <20231229094508.935@kylheku.com>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me>
<4434vmp2fl.fsf@be-well.ilk.org> <ummn5e$s6ir$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Dec 2023 17:51:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="52fd9de859b81d17f176357c065ce2c2";
logging-data="974246"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+cjS1c+AUrevTrzdGHYLIf7eU4XWikKY="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:SVJMnRMu+Pd+Af/0jfrufy1cwRM=
 by: Kaz Kylheku - Fri, 29 Dec 2023 17:51 UTC

On 2023-12-29, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> On 28.12.2023 20:11, Lowell Gilbert wrote:
>>
>> To be honest,I didn't actually understand where your problem came from
>> in the first place -- I just chose not to bring up more than one point
>> at a time. While usleep() is obsolete, it works fine, without any
>> feature test macro games, on (as far as I know) all POSIX-ish
>> systems. Certainly on recent Ubuntu, the following program compiles and
>> runs perfectly well without even any warnings with even the most extreme
>> levels of warning enabled:
>> [snip code]
>
> Here's the output of the compiler call with #define _GNU_SOURCE removed
>
> $ cc -std=c99 -o warn warn.c
> warn.c: In function ‘delay_time’:
> warn.c:368:3: warning: implicit declaration of function ‘strnlen’
> [-Wimplicit-function-declaration]
> warn.c: In function ‘main’:
> warn.c:579:5: warning: implicit declaration of function ‘usleep’
> [-Wimplicit-function-declaration]
>
> It compiles, but if I see warnings I nonetheless try to get rid of them.

This is a good plan because the implicit declaration of a function
is only a guess, which can easily be wrong. The return type is
guessed to be int (wrong for strnlen which has size_t). The number
of arguments and their types are guessed from the call, and could
be wrong. E.g. if sin is not declared then sin(0) implicity declares
it as int (int). Implicit declaration has been dropped from ISO C;
for a number of decades, it was there in support of K&R C programs.
Compiler vendors can support it as long as they like, but a diagnostic
is now required when an undeclared function is used.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

usleep (Was: Effect of CPP tags)

<umn22t$1cts2$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30439&group=comp.lang.c#30439

  copy link   Newsgroups: 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: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: usleep (Was: Effect of CPP tags)
Date: Fri, 29 Dec 2023 18:10:37 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <umn22t$1cts2$1@news.xmission.com>
References: <umet9d$3hir9$1@dont-email.me> <umk836$ehn5$1@dont-email.me> <iXBjN.109557$p%Mb.36381@fx15.iad>
Injection-Date: Fri, 29 Dec 2023 18:10:37 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1472386"; 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, 29 Dec 2023 18:10 UTC

In article <iXBjN.109557$p%Mb.36381@fx15.iad>,
Scott Lurndal <slp53@pacbell.net> wrote:
....
>You can always define your own usleep:
>
>inline int
>usleep(useconds_t microseconds)
> { etc... }

Or just:

int usleep(useconds_t microseconds);

The semicolon at the end is the key.
--
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/Pedantic

Re: Effect of CPP tags

<87o7e8voy1.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30440&group=comp.lang.c#30440

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 29 Dec 2023 10:33:26 -0800
Organization: None to speak of
Lines: 17
Message-ID: <87o7e8voy1.fsf@nosuchdomain.example.com>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me> <ummmqe$s4od$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="429276411a044e69398eca77c4a97f98";
logging-data="983545"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WZLLDjfEutcfB/3R3MsrH"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:/amMVKYD+lmZS8eJmeiaM5blZRo=
sha1:+g+j304bSDlotxYBfAlO8qaKxIk=
 by: Keith Thompson - Fri, 29 Dec 2023 18:33 UTC

David Brown <david.brown@hesbynett.no> writes:
> A useful tool that someone might like to write for this particular
> situation would be a partial C preprocessor, letting you choose what
> gets handled. You could choose to expand the code here for, say,
> _GNU_SOURCE and _BSD_SOURCE - any use of these in #ifdef's and
> conditional compilation would be expanded according to whether you
> have defined the symbols or not, leaving an output that is easier to
> understand while keeping most of the pre-processor stuff unchanged (so
> not affecting #includes, and leaving #define'd macros and constants
> untouched and therefore more readable).

The unifdef tool does some of this. (I haven't used it much.)

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Pages:123456789101112131415161718192021222324252627
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor