[Linux-cachefs] Re: [PATCH 0/12] FS-Cache: Generic filesystem caching facility

Linus Torvalds torvalds at osdl.org
Tue Nov 15 17:05:08 UTC 2005



On Tue, 15 Nov 2005, David Howells wrote:
>
> I don't think I have a need for both. Either I give you a cookie (for which
> there may be nothing in the cache); or I give you the "negative" cookie for
> which there's definitely nothing in the cache, and gracefully refuse to
> service it.
> 
> So, would you still rather I used NULL? If so, I can change it easily enough.

Yes, if you don't have real negative cookies, then just use NULL.

Think of malloc(). It doesn't return MALLOC_OUT_OF_MEMORY_COOKIE when it 
won't give you any more memory. It returns NULL.

The advantage of NULL is that people know what it is, and that the C 
language _defines_ that you can do "if (xyzzy)" to test for non-NULL. 
Conversely, the disadvantage of using a special cookie (that just happens 
to be NULL) is that the test for NULL still _works_, so now you have two 
ways of doing something and the compiler will never warn.

So in a very real sense, NULL _always_ exists. You can't make it go away 
by defining it to another name, and by using another name you just confuse 
things (if they are in fact the same).

		Linus




More information about the Linux-cachefs mailing list