SHARE
TWEET

weird.c

Phr0zen_Penguin Apr 12th, 2013 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*============================================================================
  2.   ----------------------------------------------------------------------------
  3.   weird.c - Void pointer versatility...
  4.                  (c) Damion 'Phr0z3n.Dev' Tapper, 2013.
  5.                  Email: Phr0z3n.Dev@Gmail.com
  6.  
  7.   NOTE: void* - The 'pawn' of C Programming.
  8.   ----------------------------------------------------------------------------
  9.   ============================================================================*/
  10. #define USE_SEC_API /* Comment this line if you do not have the secure libraries. */
  11.  
  12. #include <stdio.h>
  13.  
  14. void* retVal(void *); /* This is 'not so' weird... */
  15. int main(void)
  16. {
  17.         int *a;
  18.  
  19.         a = retVal((void *)2);  /* ...but this is... */
  20.  
  21. #ifdef USE_SEC_API
  22.         printf_s("%d", a); /* The secure printf function (good programming practice). */
  23. #else
  24.         /* If you are lacking the secure libraries. */
  25.         printf("%d", a);
  26. #endif
  27.  
  28.         return 0;
  29. }
  30.  
  31. void* retVal(void *nada)  /* ...because of this. */
  32. {
  33.         return (int *)(2 * (int)nada);  /* Now this is really, really weird. */
  34. }
RAW Paste Data
Top