public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* -minstd: Require a minimum std version, without being specific
@ 2022-12-21 18:33 Alejandro Colomar
  2022-12-21 18:51 ` Alexander Monakov
  2022-12-22  2:42 ` Ben Boeckel
  0 siblings, 2 replies; 8+ messages in thread
From: Alejandro Colomar @ 2022-12-21 18:33 UTC (permalink / raw)
  To: gcc; +Cc: Andrew Clayton


[-- Attachment #1.1: Type: text/plain, Size: 2087 bytes --]

Hi,

I've long had this wish: an option similar to -std, but which would not specify 
the standard.  Rather, mark a requirement that the standard be at least a version.

This would be especially useful for libraries, which might for example require 
C99 or C11 to work.  They would be able to specify -minstd=c11 in their pc(5) 
file (for use with pkgconf(1)).  That way, a program using such library, would 
be free to use -std to specify the C version that the project should be compiled 
with; maybe gnu17, maybe even gnu2x.  But if the program tries to compile under, 
say gnu89, the compiler would report an error.

If the option is repeated, the requirement will be the higher of all of them, 
using the following rules:

-  If no -minstd invocations mention gnu, -std may specify either ISO C or GNU 
C.  If any -minstd invocations mention gnu, -std can only specify GNU C.

-  -std may only specify a language version at least as high as the highest 
version specified by -minstd invocations (ignoring the dialect, that is GNU or 
ISO C).

Examples:

-minstd=c99 -minstd=gnu89
	This would be equivalent to -minstd=gnu99
	The default of -std=gnu17 would apply.

-minstd=c89 -minstd=c99
	This would be equivalent to -minstd=c99
	The default of -std=gnu17 would apply.

-minstd=gnu2x
	The default of -std=gnu17 would not be enough;
	Compilation error.

-minstd=gnu99 -std=c99
	C99 is "less" than the required GNU C99.
	Compilation error.


It could also be used by programs, to specify a minimum C version that it 
supports, while not preventing newer compilers from using newer versions.  It 
would only tell users when they try to compile in old systems that their system 
is not supported.

It is different from -std, because -std is more useful to lock a maximum version 
that is supported, rather than a minimum.  -std is normally used by projects 
that don't support recent versions of C, to force compilation with old versions.


Does it make sense to you?

Cheers,

Alex



-- 
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: -minstd: Require a minimum std version, without being specific
  2022-12-21 18:33 -minstd: Require a minimum std version, without being specific Alejandro Colomar
@ 2022-12-21 18:51 ` Alexander Monakov
  2022-12-21 18:53   ` Alejandro Colomar
  2022-12-22  2:42 ` Ben Boeckel
  1 sibling, 1 reply; 8+ messages in thread
From: Alexander Monakov @ 2022-12-21 18:51 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: gcc, Andrew Clayton



On Wed, 21 Dec 2022, Alejandro Colomar via Gcc wrote:

> Hi,
> 
> I've long had this wish: an option similar to -std, but which would not
> specify the standard.  Rather, mark a requirement that the standard be at
> least a version.
> 
> This would be especially useful for libraries, which might for example require
> C99 or C11 to work.  They would be able to specify -minstd=c11 in their pc(5)
> file (for use with pkgconf(1)).

There's already a standard, portable way to check:

#if __STDC_VERSION__ < 201710
#error C17 required
#endif

Alexander

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: -minstd: Require a minimum std version, without being specific
  2022-12-21 18:51 ` Alexander Monakov
@ 2022-12-21 18:53   ` Alejandro Colomar
  2022-12-21 19:08     ` Alejandro Colomar
  2022-12-21 19:12     ` Alexander Monakov
  0 siblings, 2 replies; 8+ messages in thread
From: Alejandro Colomar @ 2022-12-21 18:53 UTC (permalink / raw)
  To: Alexander Monakov; +Cc: gcc, Andrew Clayton


[-- Attachment #1.1: Type: text/plain, Size: 826 bytes --]

Hi Alexander,

On 12/21/22 19:51, Alexander Monakov wrote:
> 
> 
> On Wed, 21 Dec 2022, Alejandro Colomar via Gcc wrote:
> 
>> Hi,
>>
>> I've long had this wish: an option similar to -std, but which would not
>> specify the standard.  Rather, mark a requirement that the standard be at
>> least a version.
>>
>> This would be especially useful for libraries, which might for example require
>> C99 or C11 to work.  They would be able to specify -minstd=c11 in their pc(5)
>> file (for use with pkgconf(1)).
> 
> There's already a standard, portable way to check:
> 
> #if __STDC_VERSION__ < 201710
> #error C17 required
> #endif

Hmm, not my favourite to stick that in every public header file, but yes, it's 
portable.

Thanks,

Alex

> 
> Alexander

-- 
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: -minstd: Require a minimum std version, without being specific
  2022-12-21 18:53   ` Alejandro Colomar
@ 2022-12-21 19:08     ` Alejandro Colomar
  2022-12-21 19:14       ` Jonathan Wakely
  2022-12-21 19:12     ` Alexander Monakov
  1 sibling, 1 reply; 8+ messages in thread
From: Alejandro Colomar @ 2022-12-21 19:08 UTC (permalink / raw)
  To: Alexander Monakov; +Cc: gcc, Andrew Clayton


[-- Attachment #1.1: Type: text/plain, Size: 1051 bytes --]



On 12/21/22 19:53, Alejandro Colomar wrote:
> Hi Alexander,
> 
> On 12/21/22 19:51, Alexander Monakov wrote:
>>
>>
>> On Wed, 21 Dec 2022, Alejandro Colomar via Gcc wrote:
>>
>>> Hi,
>>>
>>> I've long had this wish: an option similar to -std, but which would not
>>> specify the standard.  Rather, mark a requirement that the standard be at
>>> least a version.
>>>
>>> This would be especially useful for libraries, which might for example require
>>> C99 or C11 to work.  They would be able to specify -minstd=c11 in their pc(5)
>>> file (for use with pkgconf(1)).
>>
>> There's already a standard, portable way to check:
>>
>> #if __STDC_VERSION__ < 201710
>> #error C17 required
>> #endif
> 
> Hmm, not my favourite to stick that in every public header file, but yes, it's 
> portable.

But yes, I could provide a <project/__compiler.h> "hidden" header that does all 
this stuff, then include it everywhere.  :)


> 
> Thanks,
> 
> Alex
> 
>>
>> Alexander
> 

-- 
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: -minstd: Require a minimum std version, without being specific
  2022-12-21 18:53   ` Alejandro Colomar
  2022-12-21 19:08     ` Alejandro Colomar
@ 2022-12-21 19:12     ` Alexander Monakov
  2022-12-21 19:15       ` Alejandro Colomar
  1 sibling, 1 reply; 8+ messages in thread
From: Alexander Monakov @ 2022-12-21 19:12 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: gcc, Andrew Clayton


On Wed, 21 Dec 2022, Alejandro Colomar via Gcc wrote:

> > There's already a standard, portable way to check:
> > 
> > #if __STDC_VERSION__ < 201710
> > #error C17 required
> > #endif
> 
> Hmm, not my favourite to stick that in every public header file, but yes, it's
> portable.

I don't see why you'd need that in "every public header". Public headers
should be so simple they would have no need to check C version at all, no?

Alexander

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: -minstd: Require a minimum std version, without being specific
  2022-12-21 19:08     ` Alejandro Colomar
@ 2022-12-21 19:14       ` Jonathan Wakely
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Wakely @ 2022-12-21 19:14 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: Alexander Monakov, gcc, Andrew Clayton

[-- Attachment #1: Type: text/plain, Size: 1296 bytes --]

On Wed, 21 Dec 2022, 19:08 Alejandro Colomar via Gcc, <gcc@gcc.gnu.org>
wrote:

>
>
> On 12/21/22 19:53, Alejandro Colomar wrote:
> > Hi Alexander,
> >
> > On 12/21/22 19:51, Alexander Monakov wrote:
> >>
> >>
> >> On Wed, 21 Dec 2022, Alejandro Colomar via Gcc wrote:
> >>
> >>> Hi,
> >>>
> >>> I've long had this wish: an option similar to -std, but which would not
> >>> specify the standard.  Rather, mark a requirement that the standard be
> at
> >>> least a version.
> >>>
> >>> This would be especially useful for libraries, which might for example
> require
> >>> C99 or C11 to work.  They would be able to specify -minstd=c11 in
> their pc(5)
> >>> file (for use with pkgconf(1)).
> >>
> >> There's already a standard, portable way to check:
> >>
> >> #if __STDC_VERSION__ < 201710
> >> #error C17 required
> >> #endif
> >
> > Hmm, not my favourite to stick that in every public header file, but
> yes, it's
> > portable.
>
> But yes, I could provide a <project/__compiler.h> "hidden" header that
> does all
> this stuff, then include it everywhere.  :)
>


And this works for projects that don't use pkg-config, and with all
compilers, including existing versions of gcc.

I really don't know why you'd want to enforce this outside the source
itself, with a separate non-portable tool.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: -minstd: Require a minimum std version, without being specific
  2022-12-21 19:12     ` Alexander Monakov
@ 2022-12-21 19:15       ` Alejandro Colomar
  0 siblings, 0 replies; 8+ messages in thread
From: Alejandro Colomar @ 2022-12-21 19:15 UTC (permalink / raw)
  To: Alexander Monakov; +Cc: gcc, Andrew Clayton


[-- Attachment #1.1: Type: text/plain, Size: 893 bytes --]

Hi Alexander,

On 12/21/22 20:12, Alexander Monakov wrote:
> 
> On Wed, 21 Dec 2022, Alejandro Colomar via Gcc wrote:
> 
>>> There's already a standard, portable way to check:
>>>
>>> #if __STDC_VERSION__ < 201710
>>> #error C17 required
>>> #endif
>>
>> Hmm, not my favourite to stick that in every public header file, but yes, it's
>> portable.
> 
> I don't see why you'd need that in "every public header". Public headers
> should be so simple they would have no need to check C version at all, no?

For example, I'm currently writing a library that uses C99 inline.  Compiling 
with GNU C89 inline would probably be very bad; if it works, I wouldn't trust 
that code.  (okay, I know there's -fno-gnu89-inline; but I just want to be on 
the safe side, and disallow C89/GNUC89 entirely).

Cheers,

Alex

> 
> Alexander

-- 
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: -minstd: Require a minimum std version, without being specific
  2022-12-21 18:33 -minstd: Require a minimum std version, without being specific Alejandro Colomar
  2022-12-21 18:51 ` Alexander Monakov
@ 2022-12-22  2:42 ` Ben Boeckel
  1 sibling, 0 replies; 8+ messages in thread
From: Ben Boeckel @ 2022-12-22  2:42 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: gcc, Andrew Clayton

On Wed, Dec 21, 2022 at 19:33:48 +0100, Alejandro Colomar via Gcc wrote:
> I've long had this wish: an option similar to -std, but which would not specify 
> the standard.  Rather, mark a requirement that the standard be at least a version.
> 
> This would be especially useful for libraries, which might for example require 
> C99 or C11 to work.  They would be able to specify -minstd=c11 in their pc(5) 
> file (for use with pkgconf(1)).  That way, a program using such library, would 
> be free to use -std to specify the C version that the project should be compiled 
> with; maybe gnu17, maybe even gnu2x.  But if the program tries to compile under, 
> say gnu89, the compiler would report an error.

(FD: CMake developer, ISO C++ SG15 committee member)

I'd like to see us move away from "flag soup" and instead towards more
structured information here. This request corresponds to CMake's
`C_STANDARD` target property[1] which CMake then puts together to mean
something.

Note that there are real hazards with just putting the flags like this
into `.pc` files directly. If you have a C library and say "-minstd=c99"
and I'm C++, what is supposed to happen with this flag for a C++
compilre? Does it translate to C++11 (which is the first C++ standard to
"fully contain" C99)? What if there is no answer (e.g., `-minstd=c23`)?

FWIW, my idea is to broaden the concept CMake has of "usage
requirements" to not be so CMake-centered and to encompass things like
"you need an rpath to X to use my libraries" or even "here's an entry
for `PYTHONPATH` to use my Python code". ISO C++'s SG15 has started
discussion of such things with an eye towards standardization here:

    https://github.com/isocpp/pkg-fmt

--Ben

[1]https://cmake.org/cmake/help/latest/prop_tgt/C_STANDARD.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-12-22  2:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-21 18:33 -minstd: Require a minimum std version, without being specific Alejandro Colomar
2022-12-21 18:51 ` Alexander Monakov
2022-12-21 18:53   ` Alejandro Colomar
2022-12-21 19:08     ` Alejandro Colomar
2022-12-21 19:14       ` Jonathan Wakely
2022-12-21 19:12     ` Alexander Monakov
2022-12-21 19:15       ` Alejandro Colomar
2022-12-22  2:42 ` Ben Boeckel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).