Or, nearly equivalently, C does not allow a cast expression to be the
target of an assignment. The following:
(char*)foo = some_value;
is illegal for the same reason that
(foo + 1) = some_value;
In response to that: is this cast illegal too?
/* ul is unsigned long containing pointer to string */
if ( (char*)ul == NULL )
Because although I am comfortable with both, I am unsure whether to use that
or
if ( ul == (long)NULL )
There are no lvalues in either form (you're comparing, not assigning),
so this isn't really relevant to the original question.
Given that ul is an unsigned long containing a pointer to a string,
I'd go with the first one. The second form is doing an integer
comparison of two pointer values; this is likely to work as expected
for an equality comparison, but I've worked on systems where it could
fail badly for "<" and other comparisons. (And the second form
compares an unsigned long to a signed long; that might be ok, but I'm
not going to spend the brain cells necessary to convince myself.)
Having said that, you really shouldn't be comfortable with the idea of
storing a pointer in an unsigned long variable. If you want ul to
contain a pointer to a string, why didn't you declare it as char*?
There is no guarantee that the types char* and unsigned long are even
the same size; either could be larger than the other. And although
it's legal to convert between integer types and pointer types, there
are very few guarantees about the semantics.
What problem are you trying to solve? If the answer is storing a
string pointer in an integer variable, you're very likely asking the
wrong question.