Skip to content

Feature request: Allow constexpr in C #1095

Open

Description

@sorairolake

Currently, the allow_constexpr option is available in C++ mode but not in C mode. The constexpr specifier is also available in C since C23.12 So I think it would be better if this option is available in C mode as well. Because this can be typed, unlike the #define directive.

#include <stdio.h>

#define FOO 10

int main(void) {
  printf("%d\n", FOO);
  return 0;
}

In C23 this code can be written as:

#include <stdio.h>

constexpr int FOO = 10;

int main(void) {
  printf("%d\n", FOO);
  return 0;
}

Footnotes

  1. https://en.cppreference.com/w/c/language/constexpr.html ↩

  2. Note that this is not available for functions, unlike C++. ↩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions