As for the "don't use enums as integers" silly rule, i'm sorry to say
that, but i won't follow you. ;-) Even Pascal has ord, pred and succ
that work on enum types!
They're guidelines, not hard rules. There are times not to follow them,
but it's almost never when you think it's useful. These guidelines are
for writing code that works because it's supposed to, as opposed to code
that works by accident.
In general, counting on the order of enums is not a good idea. For your
example, what happens if you turn left from EAST? What if you want to
expand what you have to include SE, NE, SW, NW, and/or points in between?
Your code has to change, and it has to change everywhere.
If you wrap direction changing in functions, then you can be safe. Let
the calling program have a token that has no meaning to it, but that it
can call the wrapper functions to manipulate and interpret (such as
providing the string that represent the current direction, or a degree
count, etc.).
C can't enforce that, though.
I don't think there is anything wrong in having ordered enums.
It's not wrong, it's just that it frequently leads to problems because
your thinking is sloppy. C's enums aren't really enums, they're a
convenient fiction with no protection. Treat them strictly as enums
(except in wrapper routines which have to know better), and you're OK.
Again, what's the point of !ptr if ptr is not a boolean, but a
pointer?? Pointers are to be compared to pointers, so ptr == NULL is OK
-------------8<-----------------
#include <stdio.h>
#include <stdlib.h>
#undef NULL
#define NULL (void *)(123)
char *foo;
int main( void )
{
printf( "foo = %p\n", foo );
if ( foo == NULL )
puts( "foo == NULL\n" );
else
puts( "foo != NULL\n" );
return 0;
}
------------->8-----------------
YMMV. !ptr is guaranteed to be true if ptr is NULL, ptr == NULL is not.