M
mario semo
Hello,
What does the C++ Norm says about the lifetime of compiler generated
temporary variables?
#include <stdio.h>
class BaseRef
{
//--------------------------------------------------------------------------
public:
//--------------------------------------------------------------------------
BaseRef()
{
printf("ctor BaseRef %p\n",this);
}
virtual ~BaseRef()
{
printf("dtor BaseRef %p\n",this);
}
void *qPtr()
{
return 0;
}
};
class Server
{
//--------------------------------------------------------------------------
public:
//--------------------------------------------------------------------------
Server()
{
}
virtual ~Server()
{
}
BaseRef queryBaseRef()
{
return BaseRef();
}
};
int main(int argc,char *argv[])
{
Server lServer;
printf("start\n");
{
// generates a temporary baseRef instance.
void * lPtr = lServer.queryBaseRef().qPtr();
printf("before }\n");
}
printf("after }\n");
printf("done\n");
return 0;
}
Here is the output of 2 different compilers:
VC9
start
ctor BaseRef 0012FF6C
dtor BaseRef 0012FF6C
before }
after }
done
VACPP
start
ctor BaseRef 12FF88
before }
dtor BaseRef 12FF88
after }
done
regards,
mario semo
What does the C++ Norm says about the lifetime of compiler generated
temporary variables?
#include <stdio.h>
class BaseRef
{
//--------------------------------------------------------------------------
public:
//--------------------------------------------------------------------------
BaseRef()
{
printf("ctor BaseRef %p\n",this);
}
virtual ~BaseRef()
{
printf("dtor BaseRef %p\n",this);
}
void *qPtr()
{
return 0;
}
};
class Server
{
//--------------------------------------------------------------------------
public:
//--------------------------------------------------------------------------
Server()
{
}
virtual ~Server()
{
}
BaseRef queryBaseRef()
{
return BaseRef();
}
};
int main(int argc,char *argv[])
{
Server lServer;
printf("start\n");
{
// generates a temporary baseRef instance.
void * lPtr = lServer.queryBaseRef().qPtr();
printf("before }\n");
}
printf("after }\n");
printf("done\n");
return 0;
}
Here is the output of 2 different compilers:
VC9
start
ctor BaseRef 0012FF6C
dtor BaseRef 0012FF6C
before }
after }
done
VACPP
start
ctor BaseRef 12FF88
before }
dtor BaseRef 12FF88
after }
done
regards,
mario semo