J
Jacek Dziedzic
Hello!
In my program I have a matrix class that can be simplified to
class Matrix {
public:
// ... plenty of methods
void diagonalize_via_LAPACK();
private:
double *internal_storage; // matrix's internal representation
// ... other fields
};
The memory at internal_storage is new'ed. The method
diagonalize_via_LAPACK calls an extern "C" function from
a third-party library (LAPACK).
This extern "C" function linked from somewhere else
DOES modify memory pointed by internal_storage. Do I need
to declare the pointer as
volatile double *internal_storage;
to prevent the compiler from making assumptions about the
contents of memory pointed by internal_storage?
I realize it would be wise to do so if it was, for
instance, modified asynchronously by a timer thread or
something completely unbeknown to the compiler. But is
it also the case with an extern "C" function, or does
the compiler "realize" that since I'm passing the pointer
as "double*" and not "const double*", the memory pointed
by it can be modified? I'm using a heavily-optimizing
compiler, so I'd rather be 100% sure!
thanks in advance,
- J.
In my program I have a matrix class that can be simplified to
class Matrix {
public:
// ... plenty of methods
void diagonalize_via_LAPACK();
private:
double *internal_storage; // matrix's internal representation
// ... other fields
};
The memory at internal_storage is new'ed. The method
diagonalize_via_LAPACK calls an extern "C" function from
a third-party library (LAPACK).
This extern "C" function linked from somewhere else
DOES modify memory pointed by internal_storage. Do I need
to declare the pointer as
volatile double *internal_storage;
to prevent the compiler from making assumptions about the
contents of memory pointed by internal_storage?
I realize it would be wise to do so if it was, for
instance, modified asynchronously by a timer thread or
something completely unbeknown to the compiler. But is
it also the case with an extern "C" function, or does
the compiler "realize" that since I'm passing the pointer
as "double*" and not "const double*", the memory pointed
by it can be modified? I'm using a heavily-optimizing
compiler, so I'd rather be 100% sure!
thanks in advance,
- J.