3

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. Any other compiler supporting these characters?

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

unique_ptr
  • 217
  • 3
  • 9

1 Answers1

2

According to this:

Rules for Naming Variable

  1. Variable name can't be a C++ keyword. For e.g. int can't be a variable name as it is a C++ keyword.
  2. Variable name must start with an alphabet (A-Z and a-z) or underscore ( _ ) sign. For e.g. var, X, _name, etc are valid variable names but 1a, $age, etc are invalid variable name.
  3. Variable names can have alphabet (A-Z and a-z), underscore ( _ ), digits (0-9) but can't have other symbols such as %, &, @ , etc. For e.g. a_01, findSum are valid variables name but name&, 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;
Blaze
  • 16,611
  • 1
  • 24
  • 44
  • Does that source apply specifically to C++ 11? At least the current draft has different rules (for example, [*all* characters are significant](http://eel.is/c++draft/lex.name#1.sentence-5)). – Max Langhof Oct 16 '18 at 08:28
  • 1
    It doesn't specify a version. I removed that significant characters part, because honestly, it surprised me, too. After searching around a bit, it seems like the real limitation actually is "at least 32 characters", but most compilers required the whole name to be significant, anyway. Thanks to you I learned why lots of old C programs had such horrible and mangled variable names - the limit was 6 significant characters back then. – Blaze Oct 16 '18 at 08:45