Given the following stripped down version of some production code..
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MIN_LOGIN_LEN 2
#define MAX_LOGIN_LEN 32
int main(void)
{
char lid[] = "c";
#ifdef MIN_LOGIN_LEN
if (strlen(lid) < MIN_LOGIN_LEN)
{
fprintf(stderr,"Login name must be at least %d characters long.\n",
MIN_LOGIN_LEN);
return 1;
}
#endif
if (strlen(lid) > MAX_LOGIN_LEN)
{
fprintf(stderr,"Login name exceeds %d characters.\n",MAX_LOGIN_LEN);
return 1;
}
return 0;
}
I get
[cdalten@localhost oakland]$ gcc -g cap3.c -o cap3
[cdalten@localhost oakland]$ ./cap3
Login name must be at least 2 characters long.
[cdalten@localhost oakland]$
Now, when I remove both MIN_LOGIN_LEN and define MAX_LOGIN_LEN in the following..
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MIN_LOGIN_LEN 2
#define MAX_LOGIN_LEN 32
int main(void)
{
char lid[] = "c";
if (strlen(lid) < MIN_LOGIN_LEN)
{
fprintf(stderr,"Login name must be at least %d characters long.\n",
MIN_LOGIN_LEN);
return 1;
}
if (strlen(lid) > MAX_LOGIN_LEN)
{
fprintf(stderr,"Login name exceeds %d characters.\n",MAX_LOGIN_LEN);
return 1;
}
return 0;
}
[cdalten@localhost oakland]$ gcc -g cap3.c -o cap3
[cdalten@localhost oakland]$ ./cap3
Login name must be at least 2 characters long.
I still get the same results. What is the point of the ifdef/endif in this case.