Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nordic characters in C++ variable names [duplicate]

Is it somehow possible to program in C++ using characters from the Nordic alphabet in class- and variable names? (specifically: æ, ø and å).

Example:

auto føø = 2;

I am using GCC > 6, which do not seem to support it. Is there another compiler supporting these characters?

(FYI: I have duckduckgoed this, but I came up empty.)

like image 776
unique_ptr Avatar asked Feb 04 '26 14:02

unique_ptr


1 Answers

According to this:

Rules for Naming A Variable

  1. A variable name can't be a C++ keyword. For example, int can't be a variable name as it is a C++ keyword.
  2. A variable name must start with an alphabet (A-Z and a-z) or underscore ( _ ) sign. For example, var, X, _name, etc. are valid variable names, but 1a, $age, etc. are invalid variable names.
  3. Variable names can have alphabet (A-Z and a-z), underscore ( _ ), digits (0-9), but they can't have other symbols, such as %, &, @ , etc. For example, a_01 and findSum are valid variable names, but name& and calc% are not allowed in C++.

So to answer your question:

Is it somehow possible to program in C++ using characters from the Nordic alphabet in class- and variable names? (specifically: æ, ø and å).

It's not portable, because the standard doesn't allow it; of course it's up to the individual compiler to allow it anyway. What often does work is using a macro instead, like this:

#define føø my_foo

And then later do

auto føø = 2;
like image 86
Blaze Avatar answered Feb 06 '26 03:02

Blaze