SHARE
TWEET

weirder.c

Phr0zen_Penguin Apr 12th, 2013 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*============================================================================
  2.   ----------------------------------------------------------------------------
  3.   weirder.c - ...and just when you think things couldn't get anymore fux0r3d.
  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. #include <stdlib.h> /* For calloc. */
  14.  
  15. struct  tempS
  16. {
  17.         char    *myString;
  18. }*tsp; /* This 'might' seem abnormal at first... */
  19.  
  20. void* retVal(void *, void *);
  21. int main(void)
  22. {
  23.         tsp = calloc(1, sizeof(struct tempS));  /* ...but now you see why it is not. */
  24.  
  25. #ifdef USE_SEC_API
  26.         printf_s("%d\n", retVal((void *)1, (void *)2)); /* The secure printf function (good programming practice). */
  27.         printf_s("%llf\n", *(long double *)retVal((void *)2, NULL)); /* The 'weirder'ness starts here... */
  28.         printf_s("%s\n", retVal((void *)3, NULL)); /* ...continues here... */
  29.         printf_s(retVal(NULL, NULL));
  30. #else
  31.         /* If you are lacking the secure libraries. */
  32.         printf("%d\n", retVal((void *)1, (void *)2));
  33.         printf("%llf\n", *(long double *)retVal((void *)2, NULL));
  34.         printf("%s\n", retVal((void *)3, NULL));
  35.         printf(retVal(NULL, NULL));    
  36. #endif
  37.  
  38.         free(tsp); /* The actual prototype is free(void*) so I'm not the only weird guy around here. */
  39.  
  40.         return 0;
  41. }
  42.  
  43. void* retVal(void *b, void *nada)
  44. {
  45.         switch((int)b)
  46.         {
  47.                 case 1:
  48.                         return (int *)(2 * (int)nada);
  49.                 case 2:
  50.                         {       /* ... */
  51.                                 long double     *pi = calloc(1, sizeof(long double));
  52.  
  53.                                 *pi = (long double)22 / (long double)7;
  54.  
  55.                                 return pi;
  56.                         }
  57.                 case 3:
  58.                         return tsp->myString = "Hello World!";  /* ... */
  59.                 default:
  60.                         return "U R Phroz3n!"; /* ...it doesn't end here.  It lives forever in your mind. */
  61.         }
  62. }
RAW Paste Data
Top