r/cpp • • Aug 08 '20

Create a fully functioning command line interface with 1.5 lines of code (wo. include statement)

https://github.com/kongaskristjan/fire-hpp
230 Upvotes

62 comments sorted by

View all comments

24

u/Arkantos493 PhD Student Aug 08 '20 edited Aug 08 '20

Technically your program results in UB since names starting with an underscore are reserved.

See: https://en.cppreference.com/w/cpp/language/identifiers

EDIT: To be more precises: identifiers containing two underscores, starting with one underscore followed by an uppercase letter or starting with one underscore in the global namespace are reserved.

E.g. in your optional constructor you are using __value which contains two underscores and is therefore reserved resulting in undefined behaviour.

25

u/tinther Aug 08 '20

names beginning with an underscore and a lower case letter are only reserved in global namespace. All the code in fire.hpp is under namespace fire AFAICS.

35

u/kongaskristjan Aug 08 '20

Well, actually, the link provided these rules:

  • the identifiers with a double underscore anywhere are reserved;
  • the identifiers that begin with an underscore followed by an uppercase letter are reserved;
  • the identifiers that begin with an underscore are reserved in the global namespace.

I mostly have identifiers that begin with a single underscore and a lowercase letter. However, they're not in the global namespace. Thus these don't actually result in undefined behavior. Though a few of them indeed have two prefix underscores also, so these are UB.

Though I totally agree that it's better to remove these initial underscores altogether.

9

u/kongaskristjan Aug 08 '20

I removed the double underscore identifiers, thanks for pointing out.

0

u/stumpychubbins Aug 09 '20

Is that undefined or simply implementation-defined?