Skip to content

Commit

Permalink
rcache: initialize common symbol mca_rcache_base_used_mem_hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ggouaillardet committed Mar 16, 2016
1 parent beecf1b commit 9980916
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions opal/mca/rcache/base/rcache_base_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, LLC.
* All rights reserved
* Copyright (c) 2015 Research Organization for Information Science
* Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
Expand Down Expand Up @@ -41,7 +41,7 @@

#include "opal/mca/rcache/base/static-components.h"

int mca_rcache_base_used_mem_hooks;
int mca_rcache_base_used_mem_hooks = 0;

/**
* Memory Pool Registration
Expand Down

5 comments on commit 9980916

@ggouaillardet
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hjelmn can you please double check this ?
this was reported as a non initialized common symbol, but when i checked the source code,
it seems this variable is expected to be initialized to zero.

@hjelmn
Copy link
Member

@hjelmn hjelmn commented on 9980916 Mar 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In c file scope variables are always initialized to 0.

@ggouaillardet
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am afraid i do not understand your comment

here is the output of make install

      rcache_base_frame.o: 0000000000000004 C mca_rcache_base_used_mem_hooks

mca_rcache_base_used_mem_hooks is not declared static (is this what you meant by file scope ?), and it is even declared extern in opal/mca/mpool/base/base.h

@hjelmn
Copy link
Member

@hjelmn hjelmn commented on 9980916 Mar 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any variable that is not declared in a function (stack) will always get initialized to 0. Per C99 § 6.7.8

If an object that has automatic storage duration is not initialized explicitly, its value is
indeterminate. If an object that has static storage duration is not initialized explicitly,
then:
— if it has pointer type, it is initialized to a null pointer;
— if it has arithmetic type, it is initialized to (positive or unsigned) zero;
— if it is an aggregate, every member is initialized (recursively) according to these rules;
— if it isaunion, the first named member is initialized (recursively) according to these
rules.

Per C99 § 6.2.4 the variable has static storage duration:

3 An object whose identifier is declared with external or internal linkage, or with the
storage-class specifier static has static storage duration. Its lifetime is the entire
execution of the program and its stored value is initialized only once, prior to program
startup.

@hjelmn
Copy link
Member

@hjelmn hjelmn commented on 9980916 Mar 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what I am saying is that the assumption that the variable is initialized to 0 is correct because it is always the case in C99. The common symbol stuff might indicate not that it should be initialized but that I should look and see if the variable really should be visible outside this scope.

Please sign in to comment.