Use <climits> to access information on the system's limits. E.g. to check if a long variable can fit into a short you could try
<climits>
long i; if (i<numeric_limits<short>::min() || numeric_limits<short>::max() <i) cout << i << "cannot fit into a short"