Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. #define MAL_S(type, size) (type*) malloc(sizeof(type)*size)
  5. #define MAL(type) MAL_S(type, 1)
  6. #define LAL_S(type, varname, size) type *varname = MAL(type)
  7. #define LAL(type, varname) type *varname = MAL_S(type, 1)
  8.  
  9. #define SZ 4
  10.  
  11. int main()
  12. {
  13.     /* allocating integer array with size of SZ */
  14.    
  15.     // allocate variable without being lazy
  16.     int *a = malloc(sizeof(int)*SZ);
  17.    
  18.     // macros are slaves
  19.     LAL_S(int, b, SZ);
  20.     // ^ identical to int *b = malloc(sizeof(int)*SZ);
  21.    
  22.     printf("'a' mem address: %p\n'b' mem address: %p\n", &a, &b);
  23.    
  24.     free(a);
  25.     free(b);
  26.     // ^ free allocated memory
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement