Igor Tandetnik wrote:
"Yang Ming" <ming.3.yang@gmail.com> wrote in message
news:eXgSOKJqJHA.6096@TK2MSFTNGP02.phx.gbl
I have a problem which I can't seem to find others who have the
same problem. For example, consider the following C code:
int main( )
{
#define MAX_LEN 0x8000
int i = 0;
i = MAX_LEN * 2;
return 1;
}
Is that possible to override above operator = and operator * ?
No. You can only provide user-defined operators for classes, not for
built-in types. Why would you want to, anyway? What's the goal of the
exercise?
I have a 'old' VC project(dsp) that contains many many C files. Now
I need to porting this project from 32-bit platform to 16-bit
platform. So, I would like to override operator=,+,-,*,% for checking
potential problems, e.g. runtime implicit conversion, data overflow,
truncated data, etc. For example:
void foo( void * p1, void * p2 )
{
int nResult = 0;
if( p1 &&
p2 )
{
nResult = (int)(*p1) + (int)(*p2);
}
...
}
In above example, the nResult may overflow after porting to 16-bit
platform(In theory, it may also happen even on 32-bit platform Of
course).
If it's possible to override operator +, I can check if the result
is overflow or not, then I can output a warning or something to help
me identify potential porting problems; otherwise I have to check
code line by line.
but performs the checks you want.