diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-04-26 11:47:51 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-04-26 12:04:23 +0200 |
commit | dba6bebd616fc92602c738fbdf3a898691660f92 (patch) | |
tree | 57734dff0eac7d20635bd11662ccfbab2fe1c168 /_posts | |
parent | ssh-tunnel: shorten & fix grammar (diff) | |
download | blog-dba6bebd616fc92602c738fbdf3a898691660f92.tar.gz blog-dba6bebd616fc92602c738fbdf3a898691660f92.zip |
static-vs: move TL;DR to top
Diffstat (limited to '_posts')
-rw-r--r-- | _posts/2017-06-24-static-vs-inline-vs-unnamed-namespaces.md | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/_posts/2017-06-24-static-vs-inline-vs-unnamed-namespaces.md b/_posts/2017-06-24-static-vs-inline-vs-unnamed-namespaces.md index f58c50a..fca1d7a 100644 --- a/_posts/2017-06-24-static-vs-inline-vs-unnamed-namespaces.md +++ b/_posts/2017-06-24-static-vs-inline-vs-unnamed-namespaces.md @@ -45,6 +45,23 @@ snippets: In this post I'll try to figure out whether I should use `static`, `inline` or unnamed namespaces for function definitions. +TL;DR +----- + +Here's my attempt to build an algorithm to decide whether a class/function +should be defined with either of the `static`/`inline` specifiers or put into +an unnamed namespace. +The first question I answer is: is the entity defined in a header file or in a +.cpp file? + +* **In a header** — Is it a class or a function? + * **Class** — There's no need to do anything. + * **Function** — Do you want it to behave differently for each +translation unit (may be useful, for example, for logging)? + * **Yes** — Use `static`. + * **No** — Use `inline`. +* **In a .cpp file** — Put it into an unnamed namespace. + `static` -------- @@ -210,23 +227,6 @@ of a function/class, including their own local static variables, etc. * Defining different classes with the same name in different translation units (without utilizing unnamed namespaces) is undefined behavior. -Conclusion ----------- - -Here's my attempt to build an algorithm to decide whether a class/function -should be defined with either of the `static`/`inline` specifiers or put into -an unnamed namespace. -The first question I answer is: is the entity defined in a header file or in a -.cpp file? - -* **In a header** — Is it a class or a function? - * **Class** — There's no need to do anything. - * **Function** — Do you want it to behave differently for each -translation unit (may be useful, for example, for logging)? - * **Yes** — Use `static`. - * **No** — Use `inline`. -* **In a .cpp file** — Put it into an unnamed namespace. - Tricky cases ------------ |