Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #define MAL_S(type, size) (type*) malloc(sizeof(type)*size)
- #define MAL(type) MAL_S(type, 1)
- #define LAL_S(type, varname, size) type *varname = MAL(type)
- #define LAL(type, varname) type *varname = MAL_S(type, 1)
- #define SZ 4
- int main()
- {
- /* allocating integer array with size of SZ */
- // allocate variable without being lazy
- int *a = malloc(sizeof(int)*SZ);
- // macros are slaves
- LAL_S(int, b, SZ);
- // ^ identical to int *b = malloc(sizeof(int)*SZ);
- printf("'a' mem address: %p\n'b' mem address: %p\n", &a, &b);
- free(a);
- free(b);
- // ^ free allocated memory
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement