Skip to content

Feature request: Allow constexpr in C #1095

@sorairolake

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++.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions