#define before #include

1
2
#define _CRT_RAND_S
#include <stdlib.h> // for rand_s 

This and some other defines must be declared before certain includes. Is there a way around this, in case a previously included header had already included stdlib.h.
Probably not. Basically you need to make <stdlib.h> your first include.
I understand that, however my worry is;
Even if it is the first #include, as this is a common code I'm likely to use in a lot of projects, I would have to make sure to include the common code before including <stdlib.h>. Which I'm probable to not remember, especially if I'm not looking at the code.

Example:
common_code.h
1
2
#define _CRT_RAND_S
#include <stdlib.h> // for rand_s 


project_code.h
1
2
#include <stdlib.h> // for EXIT_SUCCESS
#include "common_code.h"  


I was thinking I could possibly #undef something in particular before defining _CRT_RAND_S.
You could put those two lines in a header of their own and include the header everywhere.
Topic archived. No new replies allowed.