#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <errno.h>

#define STRTOLD(str, fits, l, d)    \
    errno = 0;                      \
    l= strtol(argv[1], NULL, 10);   \
    if (errno == ERANGE) {          \
        d= strtod(argv[1], NULL);   \
        fits = 0;                   \
    } else {                        \
        fits = 1;                   \
    }                               \

int main(int argc, char** argv)
{
    long l;
    double d;
    int fits;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <number>\n", argv[0]);
        return 1;
    }

    STRTOLD(argv[1], fits, l, d);
    if (fits) {
        printf("Fits into a long: %ld\n", l);
    } else {
        printf("Does not fit into a long, made it a double: %.0f\n", d);
    }
    return 0;
}
