From my understanding, preprocessor directives are used to modify source code before its compiled. I'm writing some code of an assignment, but my macro causes errors. In my assignment I have to write several files with main() with identical variables. I want to use macros like this.
#define SETUP (i)\
char* memory = (char*) malloc(sizeof(char)*(i));\
char* memory2 = (char*) malloc(sizeof(char)*(i))
#define CLOSE ()\
free(memory);\
free(memory2)
int main () {
int i = 7;
SETUP(i);
/****************************/
Do stuff with memory and memory2
/*****************************/
CLOSE();
}
this way I can make changes to the beginning and end of each file's main() without having to change each one. Can someone tell me what I don't understand?