|
-
September 6th, 2004, 08:43 PM
#1
using the NULL function in C
Hi I am trying to use the Null function in a for statement which is below but I keep getting the error 'warning: comparison between pointer and integer'
for(i = 0; i == NULL; i++)
it would be great if some one could tell me how to fix it thanks
-
September 6th, 2004, 08:59 PM
#2
Re: using the NULL function in C
In C, NULL is being defined as a void pointer to 0. As a result, the data types both for i and NULL don't match and the compiler generates a warning.
Code:
#define NULL ((void *)0)
BTW, why do you have to compare i=0 with NULL. The code within the for-loop only executes once which is exactly the same as executing the same code without the for-loop.
-
September 7th, 2004, 03:23 AM
#3
Re: using the NULL function in C
And why compare it with NULL, anyway? What's wrong with "0"?
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|