Categories: Mozilla Development

Not using underscores to start #defines

Bug 492625 was a rather easy fix, but one from which I tried to gleam as much as I could from nonetheless. Some /storage/* header files used defines with leading underscores. I used the following regular expression in the search and replace:

Find: (\s+)(_+)(moz\w.+_h)(_+)
Replace With: \1\3

What was interesting was that MXR suggested that there were 72 changes to be made, but the above regex only caught 63. It was only after doing all the manual labor of  combing through the list that I realized that I could have simply done a regex search for lines starting with #define (duh) to determine the source of the discrepancy. It turns out that there were some #defines without the leading underscore but having a trailing one.

It was also interesting trying to find the document defining the C++ standard. I ended up at the JTC1/SC22/WG21 – The C++ Standards Committee page which had the relevant text in the “17.6.3.3.2 Global names” section. Stack overflow was the key pointer as to exactly where the relevant info was:

Certain sets of names and function signatures are always reserved to the implementation:

  • Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter (2.12) is reserved to the implementation for any use.
  • Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.

Article info



Leave a Reply

Your email address will not be published. Required fields are marked *