From 9b3ad53e855764e46a9febe395b88d3ca1aeaf45 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 24 Jun 2017 22:54:43 +0300 Subject: add post "static vs. inline vs. namespace {" Also includes a bunch of includes to easily add grouped code snippets to a post. They were present before, but I wiped them away during the recent major history rewriting which I still regret about. --- .../inline/shared.hpp | 7 +++++++ .../inline/weird/another.cpp | 13 +++++++++++++ .../inline/weird/another.hpp | 3 +++ .../inline/weird/main.cpp | 15 +++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 _posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/shared.hpp create mode 100644 _posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.cpp create mode 100644 _posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.hpp create mode 100644 _posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/main.cpp (limited to '_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline') diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/shared.hpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/shared.hpp new file mode 100644 index 0000000..91313f2 --- /dev/null +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/shared.hpp @@ -0,0 +1,7 @@ +#pragma once + +inline int shared() +{ + static int n = 0; + return ++n; +} diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.cpp new file mode 100644 index 0000000..668516a --- /dev/null +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.cpp @@ -0,0 +1,13 @@ +#include "another.hpp" + +#include + +inline void shared() +{ + std::cout << "another.cpp: shared()\n"; +} + +void another() +{ + shared(); +} diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.hpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.hpp new file mode 100644 index 0000000..9c26d3f --- /dev/null +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.hpp @@ -0,0 +1,3 @@ +#pragma once + +void another(); diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/main.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/main.cpp new file mode 100644 index 0000000..4e32fb5 --- /dev/null +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/main.cpp @@ -0,0 +1,15 @@ +#include "another.hpp" + +#include + +inline void shared() +{ + std::cout << "main.cpp: shared()\n"; +} + +int main() +{ + shared(); + another(); + return 0; +} -- cgit v1.2.3