The Fix for the Aliasing Problem in C


/**********************************************

The Fix for the ailiasing problem in C.

Output:

3

2

**********************************************/

#include < stdio.h >

int main()

{

   /* Use a Local Variable instead */

   int LocalVar1 = 2;
   
   /* Another Local Variable */

   int LocalVar2 = 2;  
   
   /* call AliasingFunction with the Global Variable as a parameter */

   AliasingFunction(LocalVar1, LocalVar2); 

   return 0;

}

void AliasingFunction(int& InputVar1, int& InputVar2)

{

   /* Uses both local variables */

   InputVar1 = InputVar2 + 1;  
   printf("%i\n", InputVar1);
   printf("%i\n", InputVar2);

}

These pages were edited for style and content by Allan Caine, Laura Drever, Gorana Jankovic, Megan King, and Marie Lewis.
The original authors of these pages were Graeme Humphries, Chantal Laplante, Chris Mills, and Melvin Lenz.

Last Modified: Wednesday, June 7th 23:45:30

Copyright 2000 Department of Computer Science, University of Regina.


[CS Dept Home Page]