J
J. Campbell
From reading this forum, it is my understanding that C++ doesn't
require the compiler to keep code that does not manifest itself in any
way to the user. For example, in the following:
{
for(int i = 0; i < 10; ++i){
std::cout << i << std::endl;
for(int j = 0; j < 0x7fffffff; ++j){}
}
}
since j is not "used" the compiler can simply get rid of the j-loop.
The question is this: Can an optimizing compiler ignore a memset()
command if the memory pointed to is never again accessed after the
memset() command?
For example, in the following code:
int main(){
int* a = new int[100];
// some code that uses a
memset(a, 0, 100 * sizeof(*a));
delete [] a;
return 0;
}
is the compiler *obligated* to overwrite the memory used by a before
the program returns, or can the memset line be "optimized away" since
that memory isn't used to produce output later in the program?
The real question is can memset be used to assure that a program's
data is purged from memory before exiting?
require the compiler to keep code that does not manifest itself in any
way to the user. For example, in the following:
{
for(int i = 0; i < 10; ++i){
std::cout << i << std::endl;
for(int j = 0; j < 0x7fffffff; ++j){}
}
}
since j is not "used" the compiler can simply get rid of the j-loop.
The question is this: Can an optimizing compiler ignore a memset()
command if the memory pointed to is never again accessed after the
memset() command?
For example, in the following code:
int main(){
int* a = new int[100];
// some code that uses a
memset(a, 0, 100 * sizeof(*a));
delete [] a;
return 0;
}
is the compiler *obligated* to overwrite the memory used by a before
the program returns, or can the memset line be "optimized away" since
that memory isn't used to produce output later in the program?
The real question is can memset be used to assure that a program's
data is purged from memory before exiting?