for(;0;) printf("hello");

M

Mallesh

Spidey said:
Thanks for all of your suggestions, and i learned a lot of thing i must
consider before posting a query in any discussion group.

It was my fault, i just typed the code and press (ctrl+f9)
(compile+make+execute) and i get that hello in my screen; without
examining anymore i posted the query which was a big mistake;

The code which is executing was not the real one................


sorry, i wont repeat it.


"Never underestimate the power of human stupidity"
Finally u got the lesson, think twice before posting.
 
C

Christopher Benson-Manica

Simon Biber said:
#include <stdio.h>
int main(void)
{
int arr[5];
printf("%d\n", (int)sizeof arr);
printf("%d\n", (int)sizeof &arr);
return 0;
}
Borland C/C++ 5.5: 20, 20 (wrong)

That is very surprising. I know (from bitter experience) that the
5.4.1 compiler that shipped (AFAIK) with C++ Builder 4 is horribly
bug-ridden, but it seems unforgivable that such an egregious bug was
not fixed in the 5.5 release, free or otherwise.
 
A

Ancient_Hacker

Spidey said:
for(;0;)
printf("hello");

even the condition s wrong i get a hello printed on the screen
y s this happening

this could happen if some malicious person went into your stdio.h file
(which you probably included but didnt show) and they added a line
something like: #define for(x).

Either that or the compiler is incorrectly optimizing the code and
somehow falling thru the code the first time.
 
J

jmcgill

Chris said:
Opinions differ.

They're certainly proper syntax. Sometimes they are also necessary.
Appendectomies are also sometimes necessary.

Putting braces around statements does not cause you to lose your appendix.
 
B

bart.kowalski

Richard said:
jmcgill said:
Would it kill you to use curly braces?

Since a parallel reply responds negatively to your suggestion, I thought you
might welcome some support for your position.

Strange as it may seem, not everyone is an expert C programmer. A
maintenance guy in a hurry, confronted with this code:

for(image = 0; image < numimages - 1; image++)
for(y = 0; y < height; y++)
for(x = 0; x < width; x++)
if(img[image].pixel[y][x] & ALPHA)
img[image].pixel[y][x] =
alpha_blend(img[image].pixel[y][x],
img[image + 1].pixel[y][x],
img[image].alpha);

could be forgiven for adding a statement immediately under the alpha_blend
call, on the (incorrect) assumption that it would form part of the inner
loop - and he is especially likely to make this mistake if he has, say, a
Python background.

If the code were like this:

for(image = 0; image < numimages - 1; image++)
{
for(y = 0; y < height; y++)
{
for(x = 0; x < width; x++)
{
if(img[image].pixel[y][x] & ALPHA)
{
img[image].pixel[y][x] =
alpha_blend(img[image].pixel[y][x],
img[image + 1].pixel[y][x],
img[image].alpha);

}
}
}
}

that mistake would be much more difficult to make.

In my opinion, it's a good habit to get into. Obviously, some people's
mileage varies.

Agreed. But I would also like to add that in code like this:

/* ... */
}
}
}
}
}
}

Comments to indicate which block is being closed wouldn't hurt.

Regards,
Bart.
 
R

Richard Heathfield

(e-mail address removed) said:

But I would also like to add that in code like this:

/* ... */
}
}
}
}
}
}

Comments to indicate which block is being closed wouldn't hurt.

Fair comment. I guess there are still a few people left who don't use vim.
 
R

Registered User

Spidey said:
for(;0;)
printf("hello");

even the condition s wrong i get a hello printed on the screen
y s this happening

Simon said:
Turbo C is known to be buggy.

Yeah, this is what happens in Turbo C 3.0, although it does warn about
"unreachable code".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top