Heh heh, after doing C for so long this is the kind of stuff that prevented me from making any serious headway in C++:
http://www.regdeveloper.co.uk/2006/08/0 ... lus_loops/


int i;
blah;
blah
if (i == NULL)
printf("Huh?\n");
i = 0;
//do something with i

but if we're still talking about instantiating it while declaring it in a for loop declaration it wouldnt matter anyhow.ZiaTioN wrote:If you want technical wrap your head around this fact:
Some consider it bad practice to assign variables during instantiation
Ex: int i = 0;
Why you ask? Good question. The way most compilers interpret 0 these days is the exact same way they interpret NULL. So if you were to declare a variable 0 during instantiation and then later do a check for (i == NULL), you would have a false positive. In some minute instances this can cause an issue.
So actually my statement above about setting the variable to 0 during instantiation could be considered bad practice...


Master of Reality wrote:but if we're still talking about instantiating it while declaring it in a for loop declaration it wouldnt matter anyhow.ZiaTioN wrote:If you want technical wrap your head around this fact:
Some consider it bad practice to assign variables during instantiation
Ex: int i = 0;
Why you ask? Good question. The way most compilers interpret 0 these days is the exact same way they interpret NULL. So if you were to declare a variable 0 during instantiation and then later do a check for (i == NULL), you would have a false positive. In some minute instances this can cause an issue.
So actually my statement above about setting the variable to 0 during instantiation could be considered bad practice...
#include <stdio.h>
int main () {
int i;
for (; i == (int)NULL; i++) {
printf("Iteration: %d\n", i);
if (i==(int)NULL) {
printf("I am NULL!\n");
break;
}
}
return 1;
}
#include <stdio.h>
int main () {
int i;
for (i=0; i == (int)NULL; i++) {
printf("Iteration: %d\n", i);
if (i==(int)NULL) {
printf("I am NULL!\n");
break;
}
}
return 1;
}
#include <stdio.h>
int main () {
for (int i=0; i == (int)NULL; i++) {
printf("Iteration: %d\n", i);
if (i==(int)NULL) {
printf("I am NULL!\n");
break;
}
}
return 1;
}
instance.c:4: error: ‘for’ loop initial declaration used outside C99 mode

Users browsing this forum: No registered users and 1 guest