is there a way in C++ to make it obvious that certain headers must be ordered exactly as shown, and reordering them will break the program?
For example:
// WARNING , THE TWO HEADERS BELOW MUST BE IN THIS ORDER EXACTLY.
#include <winsock2.h>
#include <windows.h>
// END WARNING.
#include <iphlpapi.h>
#include <stdio.h>
#include <stdint.h>
#pragma comment(lib, "Ws2_32.lib")
Is what I have right now, but I feel like C++ SHOULD have a feature to group headers together, something like:
#include_order <winsock2.h, windows.h>
#include <windows.h>
#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdint.h>
#pragma comment(lib, "Ws2_32.lib")
This way, no matter how people rearrange your code in the future, as long as the enforcement is first, the code won't break.
This is trivial enough to write a preprocessor for, but I was wondering if I can do this already without writing my own.
full code:
// WARNING , THE TWO HEADERS BELOW MUST BE IN THIS ORDER EXACTLY.
#include <winsock2.h>
#include <windows.h>
// END WARNING.
#include <iphlpapi.h>
#include <stdio.h>
#include <stdint.h>
#pragma comment(lib, "Ws2_32.lib")
int main()
{
return 0;
}
standard way to deal with the issue: (WIN32_LEAN_AND_MEAN does seem like a misnomer)
/* this definition must precede any includes. */
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <windows.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdint.h>
#pragma comment(lib, "Ws2_32.lib")
int main()
{
return 0;
}