OpenSSL Communities
Mon 19 May 2025 3:37PM

Switching from ansi-c to c-99 discussion

AA Anton Arapov Public Seen by 19

PY

Paul Yang
<span class="translation_missing" title="translation missing: en.poll_proposal_options.sooner the better">Sooner The Better</span>
Mon 19 May 2025 7:30AM

I don't think the break will be that significant. At least we can try it and see if it's possible to switch for minor releases.

VD

Viktor Dukhovni
<span class="translation_missing" title="translation missing: en.poll_proposal_options.sooner the better">Sooner The Better</span>
Mon 19 May 2025 7:30AM

If anything, doing this sooner in a non-LTS release, gives us maximal time to iron out any impediments to having this land in the next LTS, so I would NOT defer this to 4.0. This does not introduce an ABI change, my expectation is that applications built against OpenSSL 3.5 and C90 compilers will still work with libraries built with C99.

TC

Tom Cosgrove
<span class="translation_missing" title="translation missing: en.poll_proposal_options.yes, but not now">Yes, But Not Now</span>
Mon 19 May 2025 7:30AM

I'd like us to switch, but we need to consider which platforms only support ANSI C (so would be dropped), so we should decide soon and probably defer until 4.0. Note that we may want to use a restricted set of C99, as IIRC Microsoft's C compiler wasn't fully compliant even in relatively recent versions.

TC

Tom Cosgrove Tue 20 May 2025 12:01PM

Agree with Tim that if we're already using some C99 features, we can formalise this and do it quickly (i.e. I guess my position is "pick features that are widely supported and move quickly")

SL

Shane Lontis
<span class="translation_missing" title="translation missing: en.poll_proposal_options.yes, but not now">Yes, But Not Now</span>
Mon 19 May 2025 7:30AM

While I agree with the concept of being able to write cleaner code,
It would be unfortunate if we were to introduce features that break some older platforms, so this process would be need to made public and put in an alpha release to give users time to respond.
it would be better to introduce only small changes initially in case they need to be rolled back.

DVO

David von Oheimb
<span class="translation_missing" title="translation missing: en.poll_proposal_options.sooner the better">Sooner The Better</span>
Mon 19 May 2025 7:30AM

It will clearly be helpful to officially have freedom to use C-99 features as soon as possible.
In terms of compatibility, I like the argumentation given by Viktor:

If anything, doing this sooner in a non-LTS release, gives us maximal time to iron out any impediments to having this land in the next LTS, so I would NOT defer this to 4.0. This does not introduce an ABI change, [...]

TH

Tim Hudson Mon 19 May 2025 3:40PM

Note on C99 I think we should actually have an ordered poll on the specific features we want to bring in. Using https://en.wikipedia.org/wiki/C99 as a starting point for the discussion would help.

  • inline functions

  • intermingled declarations and code: variable declaration is no longer restricted to file scope or the start of a compound statement (block)

  • several new data types, including long long int, optional extended integer types, an explicit Boolean data type, and a complex type to represent complex numbers

  • variable-length arrays (although subsequently relegated in C11 to a conditional feature that implementations are not required to support)

  • flexible array members

  • support for one-line comments beginning with //, as in BCPL, C++ and Java

  • new library functions, such as snprintf

  • new headers, such as <stdbool.h>, <complex.h>, <tgmath.h>, and <inttypes.h>

  • type-generic math (macro) functions, in <tgmath.h>, which select a math library function based upon float, double, or long double arguments, etc.

  • improved support for IEEE floating point

  • designated initializers. For example, initializing a structure by field names: struct point p = { .x = 1, .y = 2 };[5]

  • compound literals. For instance, it is possible to construct structures in function calls: function((struct x) {1, 2})[6]

  • support for variadic macros (macros with a variable number of arguments)

  • restrict qualification allows more aggressive code optimization, removing compile-time array access advantages previously held by FORTRAN over ANSI C[7]

  • universal character names, which allows user variables to contain other characters than the standard character set: four-digit \u0040 or eight-digit hexadecimal sequences \U0001f431

  • keyword static in array indices in parameter declarations[8]

We are already supporting a subset here - and what my position is we should be willing to accept all of the mainstream features but should check that they work across current CI which covers more than primary and secondary platforms - and to have a test program that lets us know separately if we have an issue. i.e. compile this program and if it compiles then your compile supports the subset we are allowed to use.

References (which I will edit as I locate more):
https://en.cppreference.com/w/c/compiler_support/99

KR

Kurt Roeckx Mon 19 May 2025 6:03PM

From https://github.com/openssl/technical-policies/pull/50?#issuecomment-1129764075

We currently use those unconditionally:

  • long long int

  • flexible array members (not sure if we still do)

  • snprintf

We use those conditionally:

  • inttypes (like uint64_t)

  • inline functions

Things that look useful that we currently don't use:

  • intermingled declarations and code

  • booleans

  • designated initializers

  • variadic macros

  • restrict

  • Unicode (wchar_t)

Things that some people might want to use:

  • one-line comments using //. The coding style doesn't allow it.

PD

Paul Dale Tue 20 May 2025 1:42AM

A strong +1 for designated initializers. These would make our tables of algorithms much nicer to read.

DB

Dmitry Belyavsky Mon 19 May 2025 8:17PM

What I really like and want to have in our code is declaration of the loop variable in the loop and boolean type.

PD

Paul Dale Mon 19 May 2025 10:17PM

We should not have an ordered poll. They are designed to get the best single choice which isn't what we're after here. Rather, each feature should be voted on separately either via multiple polls or a "score poll".

TH

Tim Hudson Tue 20 May 2025 5:31AM

@Paul Dale i agree a poll on each item would certainly be the fastest way to seeing what level of interest/support each feature has ...

SN

Sasha Nedvedicky Tue 20 May 2025 9:49AM

The way I see it, the question/poll to discuss now is dropping `-ansi` option in favor of `-std=c99`. This is the first step and first decision to be made. The additional decisions will come up once PRs with code changes will be arriving. Then we can individually discuss all c99 features we currently don't (or can not use), be it boolean type, declaration of loop variables, designated initializers etc.

TM

Tomas Mraz Tue 20 May 2025 11:55AM

@Sasha Nedvedicky IMO this is the other way around. Changing the CI should happen after we have concrete reasons to drop that CI run, not just "let's be sloppy in which C level is enforced". First we should decide which platforms are we willing to drop, then which C features we want to use and only as the last thing we should drop the -ansi CI job.

SN

Sasha Nedvedicky Tue 20 May 2025 12:03PM

But how do we discover pitfalls if we keep `-ansi` safety belt on? I think the only way to move forward is to lift `-ansi` bar and let C99 feature to slowly creep in one-by-one carefully watching the fallout and be ready to step-back/back out if we shoot too far an miss.

RL

Richard Levitte Thu 22 May 2025 4:17AM

@Tomas Mraz, just looking at https://openssl-library.org/policies/general-supplemental/platforms/, I'm willing to bet that only the most aged of the unadopted platforms may not cut it.

RL

Richard Levitte Thu 22 May 2025 4:23AM

@Tim Hudson... Heh, both you and @Kurt Roeckx have mentioned a set of features, of which I would ✅ a large majority

SN

Sasha Nedvedicky Tue 20 May 2025 2:04AM

I've just gave a CI try with this PR here:

https://github.com/openssl/openssl/pull/27659

Everything seems to remain green. The PR does 's/-ansi/-std=c99' in github workflow.

RL

Richard Levitte Tue 20 May 2025 6:44AM

For me, setting the base level at C99 means being able to clean away swathes of "compensatory" code in e_os.h, e_os2.h and other places. They... hurt

DB

Dmitry Belyavsky Tue 20 May 2025 12:33PM

I also really like syntax like this - if we could use it, it would drastically simplify our code - but I'm not sure to what extent it's supported

https://github.com/redhat-plumbers/dracut-rhel10/blob/687582799c466e215229336ad6cf6dd3e050c326/src/ossl/src/ossl-files.c#L16C1-L23C6

RL

Richard Levitte Wed 21 May 2025 5:22AM

@Dmitry Belyavsky, the cleanup attribute is a GNU C extension, so can't be assumed to exist everywhere. I agree it's nice! but...

TH

Tim Hudson Tue 20 May 2025 1:20PM

My view is that we have support to remove the prohibition on more C-99 coming in as a default position. We should check and test that a new feature makes sense to use - but the default is that anything can be proposed and absent hitting demonstrated portability issues on platforms we consider we support, then we can use them. That's my interpretation of the current status.

SN

Sasha Nedvedicky Wed 21 May 2025 1:26AM

I think the next step is to get the PR 27659 in so we can start slowly adopting C99 features. Shall we start a new poll about PR 27659?

PD

Paul Dale Wed 21 May 2025 1:35AM

I think that once this vote concludes and depending on it's result, we can either drop it, delay it or leave it to the normal review process. I don't see a need for a new poll here.