An fd_set
is an array of bits, only manipulated with FD_*
macros because C doesn't have a "bit" type. (The type is officially opaque, and could be implemented a different way - in fact winsock does implement it differently - but all unix-like OSes use the array of bits.)
So this code:
fd_set my_fds;
....
FD_SET(1024, &my_fds);
has the same problem as this code:
char my_fds[1024];
....
my_fds[1024] = 1;
assuming FD_SETSIZE
is 1024.
You will be overwriting whatever comes after the fd_set
in memory, causing a segfault if you're lucky, more subtle errors if you're not.