Allocate stuff.

Run Settings
LanguageC
Language Version
Run Command
#include <stdio.h> #include <stdlib.h> #include <strings.h> #define Allocate(VariableOrType, Size) \ (typeof(VariableOrType) *)malloc( sizeof(VariableOrType) * (Size)) #define AllocateZero(Pointer, Size) \ bzero(Pointer, (Size) * sizeof(*Pointer)) #define AllocateFree(Pointer) \ free(Pointer) typedef struct{ int size; short *array; }LengthArray; int main() { LengthArray foo = {20000, Allocate(*foo.array, foo.size) }; foo.array[foo.size-1] = 120; AllocateZero(foo.array, foo.size); //printf("Last value in Array: %hd\n", foo.array[foo.size-1] ); printf("sizeof(dereference) = %lu\n", sizeof( *foo.array )); printf("sizeof(type) = %lu\n", sizeof( short )); printf("sizeof(typeof(dereference)) = %lu\n", sizeof( typeof(*foo.array) )); printf("sizeof(typeof(type)) = %lu\n", sizeof( typeof(short) )); printf("sizeof(typeof(dereference) *) = %lu\n", sizeof( typeof(*foo.array) *)); printf("sizeof(typeof(type) *) = %lu\n", sizeof( typeof(short) *)); printf("These last two are important for casting, and they aren't possible with decltype()."); AllocateFree(foo.array); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines