| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This function is not declared outside of fs_permission.cc and thus should not be visible outside the file during the linking stage.
|
Review requested:
|
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM. Would you mind explaining the current problem? Just to not make the same mistake again
Sorry, something went wrong.
|
@RafaelGSS Of course :) When building a C++ application, each compilation unit (e.g., fs_permission.cc) is compiled separately. Then, the linker combines the resulting object files (such as fs_permission.o) into a single executable file (or static/shared library). As a rule of thumb, the visibility of symbols during the compilation phase should match the visibility of symbols during the linking phase. In this case, for example, PrintTree is not declared in any header files, so during the compilation phase, it is only visible within a single compilation unit (i.e., within fs_permission.cc). However, during the linking phase, the PrintTree symbol will be visible regardless of where it was defined, and regardless of whether it has been declared elsewhere. This can lead to subtle bugs. (I'll ignore name mangling in this section.)
Moving a function into an anonymous namespace within a compilation unit ensures that it will not be visible outside of the compilation unit during the linking phase. (In most cases, the same can be accomplished by marking the function as static, but in modern C++, we have a slight preference towards anonymous namespaces.) Properly managing visibility has other benefits, too. For example, you might want to get a compiler warning if a function is unused. However, if a function is not in an anonymous namespace and not marked as static, the compiler has to assume that it may be referenced by other compilation units, and thus cannot detect if it is unused. Making the compiler aware of the intended visibility allows better analysis of the source code. |
Sorry, something went wrong.
|
Thank you! |
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you much for explaining so well @tniessen :-)
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
This function is not declared outside of fs_permission.cc and thus should not be visible outside the file during the linking stage. PR-URL: nodejs#48874 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
This function is not declared outside of fs_permission.cc and thus should not be visible outside the file during the linking stage. PR-URL: nodejs#48874 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
This function is not declared outside of fs_permission.cc and thus should not be visible outside the file during the linking stage. PR-URL: nodejs#48874 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
This function is not declared outside of fs_permission.cc and thus should not be visible outside the file during the linking stage. PR-URL: nodejs#48874 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
This function is not declared outside of fs_permission.cc and thus should not be visible outside the file during the linking stage. PR-URL: #48874 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
| Back | FazBrowse Home | New Git URL |
This function is not declared outside of fs_permission.cc and thus should not be visible outside the file during the linking stage.