Advertisement
KanjiCoder

SANITY_CHECK/CRANE_ARM_POINTERS

Jun 10th, 2022
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.87 KB | None | 0 0
  1. //:==========================================================://
  2. //:                                                          ://
  3. //:  www.twitch.com/KanjiCoder                               ://
  4. //:                                                          ://
  5. //:  #_MAKE_SURE_I_UNDERSTAND_POINTERS_#                     ://
  6. //:                                                          ://
  7. //:  Every once and a while I do some weird stuff with       ://
  8. //:  pointers and I end up having the thought...             ://
  9. //:                                                          ://
  10. //:  "I thought I knew pointers. But maybe I don't."         ://
  11. //:                                                          ://
  12. //:  This code was written after one of those moments.       ://
  13. //:  To hopefully solidify my mental model of pointers.      ://
  14. //:                                                          ://
  15. //:  Maybe the "elaborative encoding" of thinking of         ://
  16. //:  arrays and the values they store as a big crane         ://
  17. //:  arm that selects shoes (values) by moving to            ://
  18. //:  different locations (boxes) will help someone           ://
  19. //:  besides myself.                                         ://
  20. //:                                                          ://
  21. //:==========================================================://
  22.  
  23.     #include <stdint.h>
  24.     #include <stdio.h>
  25.  
  26.     #define VOD void
  27.     #define I32 int32_t
  28.     #define P_F printf
  29.    
  30.     //:------------------------------------------------------://
  31.     //:                                                      ://
  32.     //:                                                      ://
  33.     //:                                                      ://
  34.     //:  ==================================================  ://
  35.     //:  Crane Arm Track //////////////////////////////////  ://
  36.     //:  ==================================================  ://
  37.     //:                  |                     |             ://
  38.     //:             arr[ 1 ]           &( arr[ 3 ] )         ://
  39.     //:                  |                     |             ://
  40.     //:             +----+----+           +----+----+        ://
  41.     //:             |         |           |         |        ://
  42.     //:             |         |           V         V        ://
  43.     //:  [    0    ]|    1    |[    2    ][    3    ]  <--Boxes
  44.     //:             V         V                              ://
  45.     //:  [ B B B B ][ B B B B ][ B B B B ][ B B B B ]  <--Shoes  
  46.     //:  ^         ^                                         ://
  47.     //:  |         |                                         ://
  48.     //:  +----+----+                                         ://
  49.     //:       |                                              ://
  50.     //:  32Bit_Value                                         ://
  51.     //:  (   Shoe  )                                         ://
  52.     //:                                                      ://
  53.     //:------------------------------------------------------://
  54.  
  55.     VOD set_dex(
  56.  
  57.         I32  *crane_arm_airspace_position
  58.     ){
  59.    
  60.         //:  "*" pluges crane arm down       Inserts Value   ://
  61.         //:               |                     |            ://
  62.         //: +-------------+--------------+   +--+--+         ://
  63.         //: |                            |   |     |         ://
  64.         //: V                            V   V     V         ://
  65.             (*crane_arm_airspace_position) = ( 666 );
  66.     }
  67.  
  68.  
  69.     I32 main( VOD ){
  70.  
  71.         I32  eve , odd , dex ;
  72.         I32  arr[ 10 ]={ 0 };
  73.  
  74.         for( dex = 0 ; dex <= 9 ; dex++ ){
  75.  
  76.             eve =( 0 == ( dex % 2 ) );
  77.             odd =( 1 == ( dex % 2 ) );
  78.  
  79.             if( eve ){             arr[ dex ]=( 333 );  };
  80.             if( odd ){ set_dex( &( arr[ dex ] ) );      };
  81.         };;
  82.    
  83.         for( dex = 0 ; dex <= 9 ; dex ++ ){
  84.  
  85.             P_F( "(%d):(%d)\n" , dex , arr[ dex ] );
  86.  
  87.             /** **************************************** ***
  88.             *** expected output :                        ***
  89.             ***                                          ***
  90.             ***     (0):(333)                            ***
  91.             ***     (1):(666)                            ***
  92.             ***     (2):(333)                            ***
  93.             ***     (3):(666)                            ***
  94.             ***     (4):(333)                            ***
  95.             ***     (5):(666)                            ***
  96.             ***     (6):(333)                            ***
  97.             ***     (7):(666)                            ***
  98.             ***     (8):(333)                            ***
  99.             ***     (9):(666)                            ***
  100.             ***                                          ***
  101.             *** **************************************** **/
  102.         };;
  103.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement