Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ anonymous namespace: Variables initialized to 0?

Tags:

c++

static

There is a related unanswered question here:
c++ - Variables auto-initialized to 0 in unnamed namespace? - Stack Overflow

When I have a global function pointer in C I can declare it static and it's initialized as NULL and only available for my file. In C++ I'm switching a lot of stuff to anonymous namespaces but I'm curious if they hold that same guarantee. If I have a function pointer in an anonymous namespace will it be initialized to null?

Thanks

like image 291
loop Avatar asked Dec 27 '22 17:12

loop


1 Answers

All variables with static storage duration are zero-initialized when the program starts. These include all variables declared at namespace scope (in the global namespace or in any other namespace, including an unnamed namespace).

like image 93
James McNellis Avatar answered Jan 10 '23 02:01

James McNellis