Advertisement
theobjop

IPCP.cpp

Feb 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. // &x and &y are the only preserved values.
  2. // They are pointers to the original.
  3. int isthisokay(int x, int y, int z) {
  4.     int* p_x = &x + 22;
  5.     int* p_y = &y + 22;
  6.     int* p_z = &z + 22;
  7.  
  8.     // Function pointer: 4
  9.     // Return pointer: 4
  10.     // Param1 : 4
  11.     // param2 : 4
  12.     // param3 : 4
  13.     // == 20
  14.  
  15.     printf("isthisokay: X(%d, %d) Y(%d, %d) Z(%d, %d)\n", *p_x, p_x, *p_y, p_y, *p_z, p_z);
  16.  
  17.     return x + 1;
  18. }
  19.  
  20. /**
  21.  * Puts a variable amount of parameters into an array for use by a function.
  22.  * @var int size - The amount of parameters to be read from the variable amount.
  23.  * @return A list of the parameters with array size of "size"
  24.  */
  25. int* put(int size, ...) {
  26.     int* values = new int[size];
  27.     int i = 0;
  28.  
  29.     va_list valist;
  30.     va_start(valist, size);
  31.     for (; size > 0; size--, i++) {
  32.         values[i] = va_arg(valist, int);
  33.     }
  34.     va_end(valist);
  35.  
  36.     return values;
  37. }
  38.  
  39. int main() {
  40.     IPCFunc* func = new IPCFunc(isthisokay, 3);
  41.  
  42.     int x = 1;
  43.     int y = 2;
  44.     int z = 3;
  45.     printf("beforecall: X(%d, %d) Y(%d, %d) Z(%d, %d)\n", x, &x, y, &y, z, &z);
  46.  
  47.     int* arguments = put(func->cPars, &x, &y, &z);
  48.     int t = testFunc.Invoke(arguments);
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement