# Include <reg52.h> unsigned int add (unsigned int variable1, unsigned int variable2) {unsigned long x = (unsigned long) variable1 + variable2; // C 51 when the calculated value is uncertain, it must be of the same type if (x> 0 xFFFF) return 0; elsereturn (variable1 + variable2);} void main (void) {unsigned int Var = add (65535,10); While (1) ;}// the result is 0x00 (unsigned long) variable1 // if unsigned long is removed, the storage type changes.
I recently found that I have always made low-level mistakes and the foundation is not strong!
# Include <reg52.h> unsigned int add (unsigned int variable1, unsigned int variable2) reentrant {unsigned long x = (unsigned long) variable1 + variable2; // C 51 when the calculated value is uncertain, it must be of the same type if (x> 0 xFFFF) return 0; elsereturn (variable1 + variable2);} void main (void) {unsigned int Var = add (65535,0x0155); While (1);} // The result is 0x00 // (unsigned long) variable1 // if unsigned long is removed, the storage type changes.