Mailing List Archive

C99
What are we trying to achieve:

We want the developer documentation to say what C constructs are fair game
in non-platform-specific code. This is going to be "you can use all of C89
plus the following", with an explicit list of useful features we know work.

The C dialect we use is constrained by

* platforms we support where the only compiler is inflexible (eg HP-UX)
* C++ extensions on CPAN need our headers, hence our headers must also be
conformat C++

We also can choose to be constrained by supporting older less flexible
compilers on platforms where newer compilers are available. Hence *this*
choice of C dialect is intertwined with the "platform" support choices.


Where we are now:

C compilers are rarely "C89 and not a penny more". We "cheat" somewhat
and already use or emulate what we need for:

* bool
* static inline
* static assert

We might be able to add this this list without needing any trade off between
"feature" and "platform support"

Likely gcc 3.1 or later is just fine:
https://gcc.gnu.org/c99status.html
It's the other compilers that will be "fun".

Postgres has a coding standard that might be useful:
https://www.postgresql.org/docs/13/source-conventions.html
but curiously it says

A few features included in the C99 standard are, at this time, not
permitted to be used in core PostgreSQL code. This currently includes
variable length arrays, intermingled declarations and code, // comments,
universal character names. Reasons for that include portability and
historical practices.

without listing any more details about why.


What we might like:

For each C99 feature we might like, it would be useful to *tabulate*

1) how using this would improve the code
2) what compilers/platforms don't support this directly
3) can it be emulated/worked around for them

that way we can make sensible trade-off decisions, and document the "why".

I think that the list is longer than this, and I don't know the
"hinder"/"work around" parts, but *as a start*

Feature: mixed declarations and code
Benefit: Can directly reduce line count without reducing readability,
Can indirectly make it easier to use const
Hindered by:
Work around:

Feature: member structure initialisers
Benefit: Clearer code.
Less chance of errors.
Structures can be re-ordered wit out makework.
Hindered by: frustratingly these were only recently added to C++, so we
couldn't use them in headers, even if we can use them elsewhere
Work around:

Feature: 64 bit integer types
even if slow, and just for arithmetic and bitwise operators
Benefit: certain calculations can be expressed directly
Hindered by:
Work around:

Feature: // comments
Benefit:
Hindered by:
Work around:

Feature: vararg macros
Benefit:
Hindered by:
Work around:
Re: C99 [ In reply to ]
Nicholas Clark <nick@ccl4.org> wrote:
:Feature: mixed declarations and code
:Benefit: Can directly reduce line count without reducing readability,
: Can indirectly make it easier to use const
:Hindered by:
:Work around:

We use a lot of macros, some of which introduce declarations; it would make
life a lot easier (and save on a lot of grepping) if you didn't need to know
every macro's expansion to know when you can place a declaration after them,
or a statement before them. We work around that with naming conventions
(not sure how consistently), but that makes it yet another barrier to entry
for new core developers.

:Feature: // comments
:Benefit:
:Hindered by:
:Work around:

Work around: /* ... */

More generally: I don't tend to touch XS, so it isn't obvious to me how
much this discussion affects XS developers. It's probably worth adding
a comment about that, either globally or against each feature.

Hugo
Re: C99 [ In reply to ]
On Tue, 18 May 2021 12:01:02 +0000
Nicholas Clark <nick@ccl4.org> wrote:

> Feature: mixed declarations and code

> Feature: member structure initialisers

> Feature: vararg macros

In case it is of interest, I've been using all three of these in XS
modules on CPAN for a while now, and haven't yet encountered any
platforms which complain. No doubt there are some around, but those
don't seem to be ones that report smoketest results.

Most notably, all these passes:

http://matrix.cpantesters.org/?dist=XS-Parse-Keyword+0.03

while using these features:

member initialisers + vararg macros:
https://metacpan.org/source/PEVANS/XS-Parse-Keyword-0.03/XSParseKeyword.h#L51-52

mixed declarations and code:
e.g.
https://metacpan.org/source/PEVANS/XS-Parse-Keyword-0.03/lib/XS/Parse/Keyword.xs#L292

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: C99 [ In reply to ]
On Tue, 18 May 2021 12:01:02 +0000, Nicholas Clark <nick@ccl4.org>
wrote:

> What are we trying to achieve:
>
> We want the developer documentation to say what C constructs are fair
> game in non-platform-specific code. This is going to be "you can use
> all of C89 plus the following", with an explicit list of useful
> features we know work.
>
> The C dialect we use is constrained by
>
> * platforms we support where the only compiler is inflexible (eg
> HP-UX)

1. The native AIX xlC compiler is even more restrictive

2. The native compiler on HP-UX is restrictive, but I'd like to note
that building *recent* GNU gcc is close to impossible on HP-UX. This
means that using the less restrictive GNU gcc on HP-UX is another
restriction on itself, as the most recent supported version is max
something like gcc-4.6.2

> * C++ extensions on CPAN need our headers, hence our headers must
> also be conformat C++
>
> We also can choose to be constrained by supporting older less flexible
> compilers on platforms where newer compilers are available. Hence
> *this* choice of C dialect is intertwined with the "platform" support
> choices.
>
>
> Where we are now:
>
> C compilers are rarely "C89 and not a penny more".

Some of them are in their default mode, but know/support run-time
options to extend into the C99 domain. As it stands, the hints files
know about those options.

> We "cheat" somewhat and already use or emulate what we need for:
>
> * bool
> * static inline
> * static assert
>
> We might be able to add this this list without needing any trade off
> between "feature" and "platform support"
>
> Likely gcc 3.1 or later is just fine:
> https://gcc.gnu.org/c99status.html
> It's the other compilers that will be "fun".
>
> Postgres has a coding standard that might be useful:
> https://www.postgresql.org/docs/13/source-conventions.html
> but curiously it says
>
> A few features included in the C99 standard are, at this time,
> not permitted to be used in core PostgreSQL code. This currently
> includes variable length arrays, intermingled declarations and
> code, // comments, universal character names. Reasons for that
> include portability and historical practices.
>
> without listing any more details about why.
>
>
> What we might like:
>
> For each C99 feature we might like, it would be useful to *tabulate*
>
> 1) how using this would improve the code
> 2) what compilers/platforms don't support this directly
> 3) can it be emulated/worked around for them
>
> that way we can make sensible trade-off decisions, and document the
> "why".
>
> I think that the list is longer than this, and I don't know the
> "hinder"/"work around" parts, but *as a start*
>
> ------------ --------------------------------------------------------
> Feature: mixed declarations and code
> Benefit: Can directly reduce line count without reducing
> readability, Can indirectly make it easier to use const

Increase readability by declaring variables for the scope/block they
are used in

> Hindered by:
> Work around:
>
> ------------ --------------------------------------------------------
> Feature: member structure initialisers
> Benefit: Clearer code.
> Less chance of errors.
> Structures can be re-ordered wit out makework.
> Hindered by: frustratingly these were only recently added to C++, so
> we couldn't use them in headers, even if we can use them
> elsewhere
> Work around:
>
> ------------ --------------------------------------------------------
> Feature: 64 bit integer types
> even if slow, and just for arithmetic and bitwise
> operators
> Benefit: certain calculations can be expressed directly
> Hindered by:
> Work around:
>
> ------------ --------------------------------------------------------
> Feature: // comments
> Benefit:

NONE!

> Hindered by:

Reduced consistency

> Work around:

Don't use it

> ------------ --------------------------------------------------------
> Feature: vararg macros
> Benefit:
> Hindered by:
> Work around:


--
H.Merijn Brand https://tux.nl Perl Monger http://amsterdam.pm.org/
using perl5.00307 .. 5.33 porting perl5 on HP-UX, AIX, and Linux
https://tux.nl/email.html http://qa.perl.org https://www.test-smoke.org
Re: C99 [ In reply to ]
On Tue, May 18, 2021 at 02:23:31PM +0100, Paul LeoNerd Evans wrote:
> Nicholas Clark <nick@ccl4.org> wrote:
> > Feature: mixed declarations and code
> > Feature: member structure initialisers
> > Feature: vararg macros
> In case it is of interest, I've been using all three of these in XS
> modules on CPAN for a while now, and haven't yet encountered any
> platforms which complain. No doubt there are some around, but those
> don't seem to be ones that report smoketest results.

If you're relying on CPAN testers for that you mostly won't get reports
when your code fails to build. Most testers only report when the tests
fail, and if your code won't even build the tests won't get run. The
reason for that is that we can't really tell automatically if the build
failure is because of your broken code or our missing libraries that it
tried to link against.

--
David Cantrell | http://www.cantrell.org.uk/david

NANOG makes me want to unplug everything and hide under the bed
-- brian d foy
Re: C99 [ In reply to ]
On Tue, May 18, 2021 at 2:01 PM Nicholas Clark <nick@ccl4.org> wrote:

> Feature: vararg macros
> Benefit:
> Hindered by:
> Work around:
>

Vararg macros would be very useful for making sprintf style defines
actually DWIM with PERL_NO_CONTEXT.

Leon
Re: C99 [ In reply to ]
On 5/18/21 6:01 AM, Nicholas Clark wrote:
> What are we trying to achieve:

Some of this was hashed out 6 months ago:

http://nntp.perl.org/group/perl.perl5.porters/258392

Smoke results

http://nntp.perl.org/group/perl.perl5.porters/258488

>
> We want the developer documentation to say what C constructs are fair game
> in non-platform-specific code. This is going to be "you can use all of C89
> plus the following", with an explicit list of useful features we know work.
>
> The C dialect we use is constrained by
>
> * platforms we support where the only compiler is inflexible (eg HP-UX)
> * C++ extensions on CPAN need our headers, hence our headers must also be
> conformat C++
>
> We also can choose to be constrained by supporting older less flexible
> compilers on platforms where newer compilers are available. Hence *this*
> choice of C dialect is intertwined with the "platform" support choices.
>
>
> Where we are now:
>
> C compilers are rarely "C89 and not a penny more". We "cheat" somewhat
> and already use or emulate what we need for:
>
> * bool
> * static inline
> * static assert
>
> We might be able to add this this list without needing any trade off between
> "feature" and "platform support"
>
> Likely gcc 3.1 or later is just fine:
> https://gcc.gnu.org/c99status.html
> It's the other compilers that will be "fun".
>
> Postgres has a coding standard that might be useful:
> https://www.postgresql.org/docs/13/source-conventions.html
> but curiously it says
>
> A few features included in the C99 standard are, at this time, not
> permitted to be used in core PostgreSQL code. This currently includes
> variable length arrays, intermingled declarations and code, // comments,
> universal character names. Reasons for that include portability and
> historical practices.
>
> without listing any more details about why.
>
>
> What we might like:
>
> For each C99 feature we might like, it would be useful to *tabulate*
>
> 1) how using this would improve the code
> 2) what compilers/platforms don't support this directly
> 3) can it be emulated/worked around for them
>
> that way we can make sensible trade-off decisions, and document the "why".
>
> I think that the list is longer than this, and I don't know the
> "hinder"/"work around" parts, but *as a start*
>
> Feature: mixed declarations and code
> Benefit: Can directly reduce line count without reducing readability,
> Can indirectly make it easier to use const
> Hindered by:
> Work around:
>
> Feature: member structure initialisers
> Benefit: Clearer code.
> Less chance of errors.
> Structures can be re-ordered wit out makework.
> Hindered by: frustratingly these were only recently added to C++, so we
> couldn't use them in headers, even if we can use them elsewhere
> Work around:
>
> Feature: 64 bit integer types
> even if slow, and just for arithmetic and bitwise operators
> Benefit: certain calculations can be expressed directly
> Hindered by:
> Work around:
>
> Feature: // comments
> Benefit:
> Hindered by:
> Work around:
>
> Feature: vararg macros
> Benefit:
> Hindered by:
> Work around:
>
Re: C99 [ In reply to ]
On Tue, May 18, 2021 at 03:58:14PM +0100, David Cantrell wrote:
> On Tue, May 18, 2021 at 02:23:31PM +0100, Paul LeoNerd Evans wrote:
> > Nicholas Clark <nick@ccl4.org> wrote:
> > > Feature: mixed declarations and code
> > > Feature: member structure initialisers
> > > Feature: vararg macros
> > In case it is of interest, I've been using all three of these in XS
> > modules on CPAN for a while now, and haven't yet encountered any
> > platforms which complain. No doubt there are some around, but those
> > don't seem to be ones that report smoketest results.
>
> If you're relying on CPAN testers for that you mostly won't get reports
> when your code fails to build. Most testers only report when the tests
> fail, and if your code won't even build the tests won't get run. The
> reason for that is that we can't really tell automatically if the build
> failure is because of your broken code or our missing libraries that it
> tried to link against.

Also, I think that *most* CPAN testers are using gcc or clang, few are
on (old) MSVC, and approximately zero are on AIX, HP-UX or VMS, whose
vendor compilers are the most likely candidates for "being exacting".

So it's not a wonderful sample for compiler portability testing.

Nicholas Clark
Re: C99 [ In reply to ]
On Wed, 19 May 2021 10:15:50 +0000, Nicholas Clark <nick@ccl4.org>
wrote:

> On Tue, May 18, 2021 at 03:58:14PM +0100, David Cantrell wrote:
> > On Tue, May 18, 2021 at 02:23:31PM +0100, Paul LeoNerd Evans wrote:
> >
> > > Nicholas Clark <nick@ccl4.org> wrote:
> [...]
> > > In case it is of interest, I've been using all three of these in
> > > XS modules on CPAN for a while now, and haven't yet encountered
> > > any platforms which complain. No doubt there are some around, but
> > > those don't seem to be ones that report smoketest results.
> >
> > If you're relying on CPAN testers for that you mostly won't get
> > reports when your code fails to build. Most testers only report
> > when the tests fail, and if your code won't even build the tests
> > won't get run. The reason for that is that we can't really tell
> > automatically if the build failure is because of your broken code
> > or our missing libraries that it tried to link against.
>
> Also, I think that *most* CPAN testers are using gcc or clang, few are
> on (old) MSVC, and approximately zero are on AIX, HP-UX or VMS, whose
> vendor compilers are the most likely candidates for "being exacting".

I have an HP-UX *and* an AIX machine available for anyone willing to
work on CPAN testing on those.

Note that the resources are very limited, and that running it in cron
is not really an option, unless we stop smoking core.

Both have GNU gcc as well as the OS native compiler.

> So it's not a wonderful sample for compiler portability testing.
>
> Nicholas Clark

--
H.Merijn Brand https://tux.nl Perl Monger http://amsterdam.pm.org/
using perl5.00307 .. 5.33 porting perl5 on HP-UX, AIX, and Linux
https://tux.nl/email.html http://qa.perl.org https://www.test-smoke.org
Re: C99 [ In reply to ]
On Tue, 18 May 2021 at 22:24, Paul "LeoNerd" Evans <leonerd@leonerd.org.uk>
wrote:

> On Tue, 18 May 2021 12:01:02 +0000
> Nicholas Clark <nick@ccl4.org> wrote:
>
> > Feature: mixed declarations and code
>
> > Feature: member structure initialisers
>
> > Feature: vararg macros
>
> In case it is of interest, I've been using all three of these in XS
> modules on CPAN for a while now, and haven't yet encountered any
> platforms which complain. No doubt there are some around, but those
> don't seem to be ones that report smoketest results.
>

For CPAN XS modules, there used to be a lot of problems with mixed
declarations and code on ActiveState Perl which was using a Microsoft C
compiler which didn't allow that. The ActiveState test results didn't
appear at CPAN testers and they didn't email them to people or anything. I
think that ActiveState Perl is doing something different now, the old web
pages for their ppm system don't display newer versions of modules.

I've used vararg macros:

https://metacpan.org/source/BKB/Text-Fuzzy-0.29/text-fuzzy-single.c#L146

// comments:

https://metacpan.org/source/BKB/Text-Fuzzy-0.29/text-fuzzy-single.c#L684

for nearly a decade without once encountering a problem at CPAN testers.

Incidentally there is some Solaris testing at CPAN testers and the Solaris
C compiler has some kind of very very strange problem with the dir part of
include statements like

#include "dir/file.h"

under some circumstances.
Re: C99 [ In reply to ]
On Tue, May 18, 2021 at 09:44:58AM -0600, Karl Williamson wrote:
> On 5/18/21 6:01 AM, Nicholas Clark wrote:
> > What are we trying to achieve:
>
> Some of this was hashed out 6 months ago:
>
> http://nntp.perl.org/group/perl.perl5.porters/258392

Thanks. I'd forgotten that thread, even though I participated in it.
I guess it work got overwhelming again midway, before I read this:

> http://nntp.perl.org/group/perl.perl5.porters/258488

I've incorporated those answers from VMS into my list.

I have put the current version at https://github.com/Perl/perl5/wiki/C99

One can clone this as git clone https://github.com/libav/c99-to-c89

I'd be happy if folks edit it directly, if they have useful stuff to add.


Sadly the VMS test system at 15.154.209.57 on which I once had an account
is no longer live, so I can't directly test things on VMS.

Merijn has kindly set me up accounts on HP-UX and AIX machines - an older
AIX version than the GCC compiler farm has.

The GCC compiler farm has Solaris 10 (and 11) with SunCC
(I believe dating from Sun).

All of the attached test cases build cleanly with the vendor compilers on
the AIX, HP-UX and Solaris systems I have access to.
That's *without* needing "C99" enabled.

(and curiously, only the HP-UX compiler spotted one bug that the others all
missed).

gcc 4.7 (and earlier) need --std=c99 for the for test.

As noted in the previous message, I *think* that any gcc back to 3.1
(ie 2002 era) is good enough, but it seems that some might need flags.

xlc claims to add "C99" support back in 2002.
I don't know when HP-UX added it, but I see -AC99 referenced in a document
that seems to be from 2004.


The real elephant in the room is MSVC. I'm surprised that no-one has
mentioned it yet.

I know that Microsoft had an epiphany *relatively* recently and decided to
start supporting C99, but

* I don't know when that was
* I don't know which version first supports enough
* I don't know if previous versions support any individual C99 features at all

and

my understanding is that "before Vista" several APIs that we would like to
use don't exist. Specifically to do with locales and what is needed to
emulate stat (or similar).

Hence, if for those reasons we decide to drop support for XP and earlier,
does doing *that* remove a constraint on minimum MSVC version, such that
*it* is not the blocker on all things post C89?

Nicholas Clark
Re: C99 [ In reply to ]
On Wed, 19 May 2021 at 14:30, Nicholas Clark <nick@ccl4.org> wrote:
> The real elephant in the room is MSVC. I'm surprised that no-one has
> mentioned it yet.
>
> I know that Microsoft had an epiphany *relatively* recently and decided to
> start supporting C99, but
>
> * I don't know when that was
> * I don't know which version first supports enough
> * I don't know if previous versions support any individual C99 features at all
>

I've tested each of your 8 test cases with each MSVC compiler that I have:

Microsoft Visual C++ 6.0 Professional x86 (VC6.0)
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
comments, flexible - compile ok
others - syntax errors

Microsoft Visual C++ 2003 Toolkit x86 (VC7.1)
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
comments, flexible, u64 - compile ok
others - syntax errors

Microsoft Visual C++ 2005 Express x86 (VC8.0)
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
comments, flexible, u64, variadic - compile ok
others - syntax errors

Microsoft Visual C++ 2008 Express x86 (VC9.0)
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
comments, flexible, u64, variadic - compile ok
others - syntax errors

Microsoft Visual C++ 2010 Express x86 (VC10.0)
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
comments, flexible, u64, variadic - compile ok
others - syntax errors

Microsoft Visual C++ 2012 Express x86 (VC11.0)
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.61030 for x86
comments, flexible, u64, variadic - compile ok
others - syntax errors

Microsoft Visual C++ 2013 Express x86 (VC12.0)
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.40629 for x86
variable - syntax errors
others - compile ok

Microsoft Visual C++ 2015 Express x86 (VC14.0 - yep, there wasn't a VC13.0...!)
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
variable - syntax errors
others - compile ok

Microsoft Visual C++ 2017 Community x64 (VC14.1)
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27045 for x64
variable - syntax errors
others - compile ok

Microsoft Visual C++ 2019 Community x64 (VC14.2)
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29913 for x64
variable - syntax errors
others - compile ok

These are the free versions of VC7 through VC14.2, which mainly limits
them to being x86. I have access to paid x64 versions too if you want
me to check, but I'm 99% sure the results would be the same.


> and
>
> my understanding is that "before Vista" several APIs that we would like to
> use don't exist. Specifically to do with locales and what is needed to
> emulate stat (or similar).
>
> Hence, if for those reasons we decide to drop support for XP and earlier,
> does doing *that* remove a constraint on minimum MSVC version, such that
> *it* is not the blocker on all things post C89?
>

All of the above compilers are running fine on my Windows 10 system on
my Windows 7 system before it. I suspect they would all run on Windows
Vista too.
Re: C99 [ In reply to ]
On Wed, 19 May 2021 13:30:25 +0000
Nicholas Clark <nick@ccl4.org> wrote:

> I have put the current version at https://github.com/Perl/perl5/wiki/C99

That list includes Variable Length Arrays, but it doesn't mention their
numerous drawbacks. Just like gets() they're *extremely* unsafe.

VLAs are allocated on the stack. The stack in C tends to be rather small
(in the order of a few megabytes), so it's very easy to overflow it.
There's no portable way to find out how much stack space is available.
VLAs don't signal errors, they just overflow the stack when you request
too much memory.

C11 has made VLAs optional (in C99 they were mandatory) and some
compliant compilers (e.g. Visual C++) have chosen not to implement it.

I think not only we shouldn't use them, but also we should explictly ban
them with something like "-Wvla -Werror=vla".
Re: C99 [ In reply to ]
On Wed, May 19, 2021 at 07:21:04PM +0200, Tomasz Konojacki wrote:
> On Wed, 19 May 2021 13:30:25 +0000
> Nicholas Clark <nick@ccl4.org> wrote:
>
> > I have put the current version at https://github.com/Perl/perl5/wiki/C99
>
> That list includes Variable Length Arrays, but it doesn't mention their
> numerous drawbacks. Just like gets() they're *extremely* unsafe.
>
> VLAs are allocated on the stack. The stack in C tends to be rather small
> (in the order of a few megabytes), so it's very easy to overflow it.
> There's no portable way to find out how much stack space is available.
> VLAs don't signal errors, they just overflow the stack when you request
> too much memory.

Thanks. I'd remembered that they were allocated on the stack, and that
overflowing the stack is undefined behaviour. I'd not realised that stack
size was usually small enough that this was a real risk, and that (further)
even if you attempt to guard against it, you can't (portably) because you
can't know how much stack space you have left.

I updated that page.

> C11 has made VLAs optional (in C99 they were mandatory) and some
> compliant compilers (e.g. Visual C++) have chosen not to implement it.

As Steve Hay has demonstrated.

> I think not only we shouldn't use them, but also we should explictly ban
> them with something like "-Wvla -Werror=vla".

Yes, I think that this is a good idea. I'm not going to look into it
right now, but I will try to remember to, and figure out what to probe
for, and where in our setup.

(Unless anyone else wants to beat me to it.)

Nicholas Clark
Re: C99 [ In reply to ]
On Wed, May 19, 2021 at 04:19:38PM +0100, Steve Hay via perl5-porters wrote:

> I've tested each of your 8 test cases with each MSVC compiler that I have:

Thanks. That is really useful.

If I try to re-order that into "what we get when"


Microsoft Visual C++ 6.0 Professional x86 (VC6.0)

* // comments
* flexible array members

neither of which give us any functionality we don't already have

Microsoft Visual C++ 2003 Toolkit x86 (VC7.1)

* 64 bit types (ie unsigned long long)

Microsoft Visual C++ 2005 Express x86 (VC8.0)

* variadic macros

Microsoft Visual C++ 2013 Express x86 (VC12.0)

* mixed declarations and code
* declarations in for loops
* member structure initialisers


> These are the free versions of VC7 through VC14.2, which mainly limits
> them to being x86. I have access to paid x64 versions too if you want
> me to check, but I'm 99% sure the results would be the same.

I wouldn't bother. I'm going to assume the same.

> All of the above compilers are running fine on my Windows 10 system on
> my Windows 7 system before it. I suspect they would all run on Windows
> Vista too.

Even if they don't, can they *target* Vista?


IIRC one of the reasons "we" were keen to stick to VC6.0 was because it was
the last version that could target the C runtime DLL that was shipping on
all existing Win32 versions. (Or something close to that). In that, one
could ship an EXE compiled with it, and not have to worry about using an
installer to also ship DLLs.

(Related to MS politics about who controlled the C runtime DLLs - the
OS group, or the compiler group)

I'm probably misremembering the details, but *that* also got resolved in
the past five-ish years, didn't it? In that distribution became easier
again?


Nicholas Clark
Re: C99 [ In reply to ]
Nicholas Clark <nick@ccl4.org> writes:

> On Wed, May 19, 2021 at 07:21:04PM +0200, Tomasz Konojacki wrote:
>
>> I think not only we shouldn't use them, but also we should explictly ban
>> them with something like "-Wvla -Werror=vla".
>
> Yes, I think that this is a good idea. I'm not going to look into it
> right now, but I will try to remember to, and figure out what to probe
> for, and where in our setup.
>
> (Unless anyone else wants to beat me to it.)

https://github.com/Perl/perl5/blob/v5.33.9/cflags.SH#L181

- ilmari
--
- Twitter seems more influential [than blogs] in the 'gets reported in
the mainstream press' sense at least. - Matt McLeod
- That'd be because the content of a tweet is easier to condense down
to a mainstream media article. - Calle Dybedahl
Re: C99 [ In reply to ]
On Wed, May 19, 2021 at 8:31 AM Nicholas Clark <nick@ccl4.org> wrote:

tl;dr, all 8 test programs compile without warning or error on:

$ cc/version
VSI C V7.4-001 on OpenVMS IA64 V8.4-2L1

> Sadly the VMS test system at 15.154.209.57 on which I once had an account
> is no longer live, so I can't directly test things on VMS.

You could just ask me like everyone else does :-). Or if you ssh to
eisner.decus.org, you can sign up for a free account on an Alpha, but
Alphas are rather slow by current standards and I'm not sure how easy
it would be to get enough disk space to build Perl. Small test
programs should be ok, though.

In a month or two there should be an early adopters' kit for OpenVMS
x64 that is expected to run on VirtualBox/KVM/VMWare. That should make
it easier to try things out at home.

The C99 situation on VMS, like everything else, is just a bit weirder
than elsewhere. The compiler has mostly supported C99 for well over a
decade (closer to two), while the library has been somewhat lacking in
various areas, but of course the standard has never distinguished
between the compiler and the library.

Last year there was a patch that finally introduced stdint.h, moving
to it a lot of things that had been in inttypes.h and supplying a lot
of things that were missing. fpclassify() got some attention and the
%z format specifier finally became available. va_copy is still not
available, but is expected to be on x86_64. I cannot find a link to
public release notes that describe the current state of things, but as
far as I can tell, nothing being contemplated in the 8 test programs
posted here is impacted by recent or near-term future changes.

Next year there is supposed to be a port of clang++ as the C++ option
for VMS. It would be nice to be able to continue to do a core build
with a C++ compiler even if the main interest is headers for XS.
Re: C99 [ In reply to ]
On Wed, May 19, 2021 at 08:43:29PM -0500, Craig A. Berry wrote:
> On Wed, May 19, 2021 at 8:31 AM Nicholas Clark <nick@ccl4.org> wrote:
>
> tl;dr, all 8 test programs compile without warning or error on:
>
> $ cc/version
> VSI C V7.4-001 on OpenVMS IA64 V8.4-2L1

Thanks. I updated https://github.com/Perl/perl5/wiki/C99

And it seems that the result is:

What we can use depends on the minimum MSVC version that we choose.

although your detail below says that we really can't assume *anything*
else much about header or runtime library support on VMS, without asking
specific questions.

> > Sadly the VMS test system at 15.154.209.57 on which I once had an account
> > is no longer live, so I can't directly test things on VMS.
>
> You could just ask me like everyone else does :-). Or if you ssh to

This doesn't scale that well...

(I think we both know that)

The 8 programs in question were actually battle tested on 3 OSes (and 4
compilers) and various bugs found before they even got attached.

"batch mode" isn't that useful for testing, until the kinks are ironed
out, and usually the sort of things I'm curious about are kinky and
involve ironing. (And somehow this is fun? I still don't get that bit)

> eisner.decus.org, you can sign up for a free account on an Alpha, but
> Alphas are rather slow by current standards and I'm not sure how easy
> it would be to get enough disk space to build Perl. Small test
> programs should be ok, though.

This is a *real* Alpha? I don't think that anyone else offers one of
those. That's actually useful even for (other) test programs, as I can't
remember what the alignment constraints (and similar) are for Alpha.

qemu isn't *ideal*, as it emulates "correct" behaviour "correctly".
So you can't find misaligned reads because it won't check for those, and
if it's running on something more forgiving (ie x86_64) it will fail to
fail. (undefined behaviour in C anyway, so it's legally correct. But on
real hardware this sort of thing is usually a SIGBUS)

sparc64 had been my current "winner" (ppc64 seems to handle misaligned
8 byte reads, whereas sparc64 does not), but until Merijn set me up
again on HP-UX yesterday I'd not had access to ia64, so I've not been
figuring out what it gets grumpy about.

(ia64 linux was fun, but the GCC farm no longer has that. The memory
map broke some assumptions for some code. Win. I think they had parisc
linux too once, but it seems that no-one is offering parisc anything
currently. I've never had access to test things on 64 bit IBM
hardware, and only very brief access to SuperH. Whichever OS that was
had the suckiest command line toolchain ever.)

> In a month or two there should be an early adopters' kit for OpenVMS
> x64 that is expected to run on VirtualBox/KVM/VMWare. That should make
> it easier to try things out at home.

I don't own any x86_64 hardware* :-)

> The C99 situation on VMS, like everything else, is just a bit weirder
> than elsewhere. The compiler has mostly supported C99 for well over a
> decade (closer to two), while the library has been somewhat lacking in
> various areas, but of course the standard has never distinguished
> between the compiler and the library.

IIRC this was always the problem with C99 conformance. gcc got "there"
way ahead of glibc. And re-reading Merijn's comments about building
gcc on HP-UX, along with looking for stuff online, it seems that gcc
needs a C99 "compiler" to bootstrap, and the gcc probes figure out
that HP-UX *libc* was missing parts of C99. And so we get to:

> Last year there was a patch that finally introduced stdint.h, moving
> to it a lot of things that had been in inttypes.h and supplying a lot
> of things that were missing. fpclassify() got some attention and the
> %z format specifier finally became available. va_copy is still not
> available, but is expected to be on x86_64. I cannot find a link to
> public release notes that describe the current state of things, but as
> far as I can tell, nothing being contemplated in the 8 test programs
> posted here is impacted by recent or near-term future changes.

That's nuts. '%z' can't have been *hard* work - sure, *printf C
implementations are never pretty, but 'z' will be an alias to a different
format letter. Presumably as supported VMS is all LP64, 'z' is just 'l'.

But isn't <stdint.h> just *tabulating* existing type and format string
knowledge into a standard form? It doesn't *need* any runtime additions,
does it?

Nicholas Clark

* strictly "any hardware capable of running a 64 bit kernel and VMs".
Even if working, which I'm not sure about either.
Re: C99 [ In reply to ]
On Thu, May 20, 2021 at 07:58:53AM +0000, Nicholas Clark wrote:

> What we can use depends on the minimum MSVC version that we choose.
>
> although your detail below says that we really can't assume *anything*
> else much about header or runtime library support on VMS, without asking
> specific questions.

Hence this recommendation:

https://www.nntp.perl.org/group/perl.perl5.porters/2021/06/msg260331.html

Nicholas Clark
Re: C99 [ In reply to ]
On Thu, May 20, 2021 at 02:19:01AM +0100, Dagfinn Ilmari Manns?ker wrote:
> Nicholas Clark <nick@ccl4.org> writes:
>
> > On Wed, May 19, 2021 at 07:21:04PM +0200, Tomasz Konojacki wrote:
> >
> >> I think not only we shouldn't use them, but also we should explictly ban
> >> them with something like "-Wvla -Werror=vla".
> >
> > Yes, I think that this is a good idea. I'm not going to look into it
> > right now, but I will try to remember to, and figure out what to probe
> > for, and where in our setup.
> >
> > (Unless anyone else wants to beat me to it.)
>
> https://github.com/Perl/perl5/blob/v5.33.9/cflags.SH#L181

commit 7886147fdc48d029686af31c71c808adad1a5737 (HEAD -> blead, origin/blead, origin/HEAD)
Author: Nicholas Clark <nick@ccl4.org>
Date: Fri Jun 11 12:17:44 2021 +0000

Add -Werror=vla by default. C99 variable-length arrays are dangerous.

C11 makes them optional, and MSVC doesn't support them. We can't use them
(but even if we could, we should not).

diff --git a/cflags.SH b/cflags.SH
index 96bfcd928b..162538583d 100755
--- a/cflags.SH
+++ b/cflags.SH
@@ -180,6 +180,7 @@ Intel*) ;; # # Is that you, Intel C++?
#
*) warns="-std=c89 -ansi $pedantic \
-Werror=pointer-arith \
+ -Werror=vla \
-Wextra -W \
-Wc++-compat -Wwrite-strings"
# declaration after statement is normal in C++ rather than an


I win!

I wasn't even trying to win.

(Also tested on on gcc 4.6.1 on AIX, which happens to have -Werror=vla
How old a gcc would I need to find to *not* have it?)

Nicholas Clark
Re: C99 [ In reply to ]
2021-6-12 1:47 Nicholas Clark <nick@ccl4.org> wrote:

>
> Add -Werror=vla by default. C99 variable-length arrays are dangerous.
>
>
I feel this is good because I feel risky and unstable about variable-length
arrays.
Re: C99 [ In reply to ]
I agree 100% that variable-length arrays are risky.

Sadly, it should be noted that this perfectly safe construction:

const size_t buf_size = 40;
char buf[buf_size];

is caught as an error by -Werror=vla

On Mon, 14 Jun 2021 at 01:27, Yuki Kimoto <kimoto.yuki@gmail.com> wrote:

>
>
> 2021-6-12 1:47 Nicholas Clark <nick@ccl4.org> wrote:
>
>>
>> Add -Werror=vla by default. C99 variable-length arrays are dangerous.
>>
>>
> I feel this is good because I feel risky and unstable about
> variable-length arrays.
>
>
Re: C99 [ In reply to ]
I never replied to this:

> On Mon, 14 Jun 2021 at 01:27, Yuki Kimoto <kimoto.yuki@gmail.com> wrote:
>
> >
> >
> > 2021-6-12 1:47 Nicholas Clark <nick@ccl4.org> wrote:
> >
> >>
> >> Add -Werror=vla by default. C99 variable-length arrays are dangerous.
> >>
> >>
> > I feel this is good because I feel risky and unstable about
> > variable-length arrays.

On Tue, Jun 15, 2021 at 02:19:58PM +0200, Eric Herman wrote:
> I agree 100% that variable-length arrays are risky.
>
> Sadly, it should be noted that this perfectly safe construction:
>
> const size_t buf_size = 40;
> char buf[buf_size];
>
> is caught as an error by -Werror=vla

I assume (but am not it a position to test) that this code is also an
error on all MSVC versions. (Even the current versions.)

And so, it's not that useful trying to figure out a way set gcc compiler
flags to permit the safe variants (-Wvla-larger-than=... I think) because
we don't really have much *nix specific code.

Nicholas Clark