Subject: CGAL users discussion list
List archive
- From: Fritz Mueller <>
- To:
- Subject: Re: [cgal-discuss] set_error_handler etc. in header-only mode
- Date: Sat, 7 Dec 2019 17:42:54 -0800
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
- Ironport-phdr: 9a23:HaW2DBbrrs9L1PzvxpZ86Xj/LSx+4OfEezUN459isYplN5qZoMi/bnLW6fgltlLVR4KTs6sC17ON9fmwBydbv96oizMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpTEdFQ/iOgVrO+/7BpDdj9it1+C15pbffxhEiCCybL9vIhi6txjdu8oXjIdtJKs8ywbCr2dVdehR2W5mP0+YkQzm5se38p5j8iBQtOwk+sVdT6j0fLk2QKJBAjg+PG87+MPktR/YTQuS/XQcSXkZkgBJAwfe8h73WIr6vzbguep83CmaOtD2TawxVD+/4apnVAPkhSEaPDM/7WrZiNF/jLhDrRyhuxNxzIHbbpybOvpwYK3Sf9AUS21aU8ZNTixBB5+wb4sTA+cDO+tTsonzp0EJrRu7HQSiBPnvyj5Uhn73wKY01PkhHh/C3AwkAd0OqmnfodL7NKcIUOC10KjJzTDYYvNYwzf96ZTIcxEkof2WWrJwa8XRxFApGgjYjVuQsZToMy2J2ukJqWSW7OptWfixh2I6tw19uCWjy8UwhoXRhI8YxErI+TtlzIorP9G0VU52bNy+HJdOuCyXOI17Sd44TW5yoiY10LgGtIa7fCcUzJQnwAbSa/mdfIiJ5hLvTf6RITlliH58drKzmhS//VS6xu3zUcm011lKri5bndXWqn8N0BnT5tCGSvt74EihxS6C2x7P5uxAO0w5lqrWJ4Q/zrItipYfq1nPEy3qlEnuia+ZbEQk+uym6+T9ZbXmo4eRN4FuigH/LqQvm8m/DP82MggUXmib5eW91Lj58U3+WrVKgeU6krPFv5DCOcQbuqm5DhdJ3YYs8Rm/Cy6q38kZnXkcMF1FZQmHj5PyNlHVIPH4CO+/jE62nDdqwfDGJLzhDY/XInjNireyNYp6vkVTwQ52wdFE7I9PEZkAJujyUwn/ro/2FBg8ZiKuwvr1QPBg24caVHjHVqGDMb/AtHeG/OMzMezKY5Ua7mWuY8M57uLj2Cdq0WQWerOkiMNOOSKIW89+KkDcWkLCx9IIEGMEpA07Fba4hkeDTSxWIXGoUPBlv21pOMedFY7GA7uVrvmZxi7iRM9YfGFaGFXKFm3nJd3dBqU8LRmKK8okqQQqELisT4h7i0OrvQ7+jqJpd6/ao3JA853k09dx6qvYkhRgrTE=
>>> Looking into the sources a bit, get_static_error_handler() etc. are
>>> define in header-only mode as inlines, returning references to local
>>> statics. I think this means each call could conceivably use different
>>> storage for those statics,
>>
>> No. A static variable inside a function is a unique global object. It is
>> the usual way to simulate C++17 inline variables and get singletons.
>
> Okay, good to know this is true, even for inlines -- thanks. I can do some
> experiments with a small bit of test code to verify that I understand
> correctly.
Well, what I’ve found with OS X clang so far is this:
Static variables inside a function are indeed unique if that function is
inline, but seeming *not* if that function is static inline? The CGAL
functions in question are perhaps effectively static inline because the
enclosing anonymous namespace.
Attached here is a shar archive of a small standalone test program that
illustrates the issue; this calls an inline function which prints the address
of a local static from two separate translation units. Running this on my
system shows two different addresses for the static, but if you edit to
remove the anonymous namespace around the inline function the problem goes
away.
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# get_static_int
# get_static_int/Makefile
# get_static_int/get_static_int.h
# get_static_int/main.cpp
# get_static_int/unit1.cpp
# get_static_int/unit1.h
# get_static_int/unit2.cpp
# get_static_int/unit2.h
#
echo c - get_static_int
mkdir -p get_static_int > /dev/null 2>&1
echo x - get_static_int/Makefile
sed 's/^X//' >get_static_int/Makefile << 'END-of-get_static_int/Makefile'
Xget_static_int:
X g++ main.cpp unit1.cpp unit2.cpp -o get_static_int
END-of-get_static_int/Makefile
echo x - get_static_int/get_static_int.h
sed 's/^X//' >get_static_int/get_static_int.h <<
'END-of-get_static_int/get_static_int.h'
X#ifndef GET_STATIC_INT_H
X#define GET_STATIC_INT_H
X
X#include <iostream>
X
Xnamespace {
X
Xinline int& get_static_int()
X{
X static int _static_int = 0;
X std::cout << "&_static_int: " << &_static_int << std::endl;
X return _static_int;
X}
X
X}
X
X#endif // !defined(GET_STATIC_INT_H)
END-of-get_static_int/get_static_int.h
echo x - get_static_int/main.cpp
sed 's/^X//' >get_static_int/main.cpp << 'END-of-get_static_int/main.cpp'
X#include "unit1.h"
X#include "unit2.h"
X
Xint main(int argc, const char *argv[])
X{
X unit1_call_get_static_int();
X unit2_call_get_static_int();
X return -1;
X}
END-of-get_static_int/main.cpp
echo x - get_static_int/unit1.cpp
sed 's/^X//' >get_static_int/unit1.cpp << 'END-of-get_static_int/unit1.cpp'
X#include "get_static_int.h"
X
Xint& unit1_call_get_static_int()
X{
X return get_static_int();
X}
END-of-get_static_int/unit1.cpp
echo x - get_static_int/unit1.h
sed 's/^X//' >get_static_int/unit1.h << 'END-of-get_static_int/unit1.h'
X#ifndef UNIT1_H
X#define UNIT1_H
X
Xint &unit1_call_get_static_int();
X
X#endif // !defined(UNIT1_H)
END-of-get_static_int/unit1.h
echo x - get_static_int/unit2.cpp
sed 's/^X//' >get_static_int/unit2.cpp << 'END-of-get_static_int/unit2.cpp'
X#include "get_static_int.h"
X
Xint& unit2_call_get_static_int()
X{
X return get_static_int();
X}
END-of-get_static_int/unit2.cpp
echo x - get_static_int/unit2.h
sed 's/^X//' >get_static_int/unit2.h << 'END-of-get_static_int/unit2.h'
X#ifndef UNIT2_H
X#define UNIT2_H
X
Xint &unit2_call_get_static_int();
X
X#endif // !defined(UNIT2_H)
END-of-get_static_int/unit2.h
exit
- [cgal-discuss] set_error_handler etc. in header-only mode, Fritz Mueller, 12/08/2019
- Re: [cgal-discuss] set_error_handler etc. in header-only mode, Marc Glisse, 12/08/2019
- Re: [cgal-discuss] set_error_handler etc. in header-only mode, Fritz Mueller, 12/08/2019
- Re: [cgal-discuss] set_error_handler etc. in header-only mode, Fritz Mueller, 12/08/2019
- Re: [cgal-discuss] set_error_handler etc. in header-only mode, Marc Glisse, 12/08/2019
- Re: [cgal-discuss] set_error_handler etc. in header-only mode, Fritz Mueller, 12/08/2019
- Re: [cgal-discuss] set_error_handler etc. in header-only mode, Marc Glisse, 12/08/2019
- Re: [cgal-discuss] set_error_handler etc. in header-only mode, Fritz Mueller, 12/08/2019
- Re: [cgal-discuss] set_error_handler etc. in header-only mode, Fritz Mueller, 12/08/2019
- Re: [cgal-discuss] set_error_handler etc. in header-only mode, Marc Glisse, 12/08/2019
Archive powered by MHonArc 2.6.18.