473,416 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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

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

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

Sep 10 '06 #1
51 4030
Spidey said:
for(;0;)
printf("hello");

even the condition s wrong i get a hello printed on the screen
y s this happening
Y h n p e c.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 10 '06 #2
Richard Heathfield wrote:
Spidey said:
for(;0;)
printf("hello");

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

Y h n p e c.
Th s n exl rpl ; i ws i hd tht f it mslf.

Sep 10 '06 #3
Richard Heathfield wrote:
Spidey said:
>for(;0;)
printf("hello");

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

Y h n p e c.
"You have not posted entire code."?

#include <stdio.h>

int main(void)
{
for(;0;)
printf("hello");

return 0;
}

I tried it on 4 different compilers and none of them printed hello on
the screen. One of them warned about unreachable code.

--
Simon.
Sep 10 '06 #4
Spiros Bousbouras wrote:
Th s n exl rpl ; i ws i hd tht f it mslf.
I cannot understand this at all.
What's the meanning please ...

Sep 10 '06 #5
Aman JIANG wrote:
Spiros Bousbouras wrote:
Th s n exl rpl ; i ws i hd tht f it mslf.

I cannot understand this at all.
What's the meanning please ...
You mean you can understand Y h n p e c ?

Sep 10 '06 #6
Aman JIANG wrote:
Spiros Bousbouras wrote:
>Th s n exl rpl ; i ws i hd tht f it mslf.

I cannot understand this at all.
What's the meanning please ...
"This is an excellent reply; I wish I had thought of it myself."

The problem with communicating in such abbreviated forms is that it is
difficult and slow for to read for some and impossible for others.

--
Simon.
Sep 10 '06 #7
Simon Biber said:
Richard Heathfield wrote:
>Spidey said:
>>for(;0;)
printf("hello");

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

Y h n p e c.

"You have not posted entire code."?
Not what I had in mind, although you did get the first three words right.

As you have demonstrated, the more letters that are gratuitously omitted
from the words of an article, the harder it is to decide what the author
meant.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 10 '06 #8

Richard Heathfield wrote:
Simon Biber said:
Richard Heathfield wrote:
Spidey said:

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

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

Y h n p e c.
"You have not posted entire code."?

Not what I had in mind, although you did get the first three words right.
"You have not provided enough context" ?

--
Bill Pursell

Sep 10 '06 #9
Simon Biber posted:
#include <stdio.h>

int main(void)
{
for(;0;)
printf("hello");

return 0;
}

I tried it on 4 different compilers and none of them printed hello on
the screen. One of them warned about unreachable code.

Lookup how a "for" loop works and all will become clear.

HINT: The conditional to be tested in the above snippet is always false.

--

Frederick Gotham
Sep 10 '06 #10
am using turbo c3 n it wont put up any warning.
and the code produced the hello output on my screen

Sep 10 '06 #11
Spidey wrote:
am using turbo c3 n it wont put up any warning.
and the code produced the hello output on my screen
Are you tidyspidey ?

Sep 10 '06 #12
Spidey posted:
am using turbo c3 n it wont put up any warning.
and the code produced the hello output on my screen

Speak English.

--

Frederick Gotham
Sep 10 '06 #13
"Spidey" <am********@gmail.comwrites:
for(;0;)
printf("hello");

even the condition s wrong i get a hello printed on the screen
y s this happening
Your compiler is broken? You are not using C compiler but some
compiler for a /type-name-here/ language which was developed 666 hours
ago by a crazy programmer who wants to take over the World? You have
put ';' after ')' and haven't noticed it?

BTW. SAA#1.

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
Sep 10 '06 #14
Michal Nazarewicz posted:
You have put ';' after ')' and haven't noticed it?

I see nothing wrong with the code fragment:

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

--

Frederick Gotham
Sep 10 '06 #15
Spidey wrote:
>
am using turbo c3 n it wont put up any warning.
and the code produced the hello output on my screen
What is it? What code? What is turbo c3 n? Why are the wonts of
'it' of interest? (Possibly you meant won't?) Without context your
post is meaningless.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com
Warning: Do not use Ultimate-Anonymity
They are worthless spammers that are running a scam.

Sep 10 '06 #16
Bill Pursell said:
>
Richard Heathfield wrote:
>Simon Biber said:
Richard Heathfield wrote:

Y h n p e c.

"You have not posted entire code."?

Not what I had in mind, although you did get the first three words right.

"You have not provided enough context" ?
Gv th mn a bnn!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 10 '06 #17
Frederick Gotham said:
Simon Biber posted:
>#include <stdio.h>

int main(void)
{
for(;0;)
printf("hello");

return 0;
}

I tried it on 4 different compilers and none of them printed hello on
the screen. One of them warned about unreachable code.


Lookup how a "for" loop works and all will become clear.
Simon knows how a for-loop works.
HINT: The conditional to be tested in the above snippet is always false.
Did you actually /read/ the original article in this thread?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 10 '06 #18
Simon Biber said:

<snip>
>
#include <stdio.h>

int main(void)
{
for(;0;)
printf("hello");

return 0;
}

I tried it on 4 different compilers and none of them printed hello on
the screen. One of them warned about unreachable code.
On reflection, and after entering into mind-reader mode, I think I know why
the OP is getting the result that he is in fact getting; if I am right, he
hasn't pasted the code he actually compiled; he's typed, from scratch, the
code he /thought/ he compiled; the style of this paragraph will, I think,
indicate to you what I think the problem is.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 10 '06 #19
Richard Heathfield <in*****@invalid.invalidwrites:
[...]
Gv th mn a bnn!
Give the man a bunny?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 10 '06 #20
Keith Thompson wrote:
Richard Heathfield <in*****@invalid.invalidwrites:
[...]
Gv th mn a bnn!

Give the man a bunny?
Banana !

Sep 10 '06 #21
"Spidey" <am********@gmail.comwrites:
for(;0;)
printf("hello");

even the condition s wrong i get a hello printed on the screen
y s this happening
Your problem is that you don't yet understand how this newsgroup works.

Please don't use silly abbreviations. This is a technical discusssion
forum, not a chat room. Most of us can guess that "s" means "is" and
"y" means "why", but not everyone here has English as a first
language, and those of us who do have better things to do with our
time than figuring out what your abbreviations mean. (That's what
people have been trying to tell you with responses like
"Y h n p e c.".) If you want our help, take the time to write plain
English. (We won't complain about minor spelling and grammatical
errors.) Proper capitalization and punctuation are also very helpful.

What you *should* have written was something like this:

Even the condition is wrong. I get a "hello" printed on the
screen. Why is this happening?

(The first sentence is still unclear, but at least we can understand
the words.)

If you post a followup, provide context. You need to quote the article
you're replying to, or at least enough of it so that your followup
makes sense to someone who hasn't seen the previous article (but
delete anything that's not relevant to your reply). The Google Groups
interface does this for you. <http://cfaj.freeshell.org/google/has
some good links. See also <http://www.caliburn.nl/topposting.html>.
And see most of the articles in this newsgroup for examples of how
to do it right.

If you post a code sample, don't try to re-type it; copy and paste the
*exact* code that you compiled and executed. We can't tell which
errors were in your original code and which were introduced when you
transcribed it; don't ask us to guess. If at all possible, post a
small complete program that we can try, not just a code fragment.
Very often the actual error is not where you think it is. (If you
knew where the error was, you wouldn't have to ask us.)

I'm going to make a guess about what your problem is. You posted
this:

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

but your program really contains this:

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

The semicolon on the first line indicates a null statement, which is
the statement controlled by the for loop. The printf() call follows
the for loop; it's not part of it. So you do nothing zero times, then
call printf() unconditionally.

(Why would you write "for(;0;)" anyway? There are easier ways to do
nothing.)

Recommended reading:

http://clc-wiki.net/wiki/Introduction_to_comp.lang.c
http://www.c-faq.com/

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 10 '06 #22
"Spiros Bousbouras" <sp****@gmail.comwrites:
Keith Thompson wrote:
>Richard Heathfield <in*****@invalid.invalidwrites:
[...]
Gv th mn a bnn!

Give the man a bunny?

Banana !
Give the banana a bunny?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 10 '06 #23
Frederick Gotham <fg*******@SPAM.comwrites:
Michal Nazarewicz posted:
>You have put ';' after ')' and haven't noticed it?

I see nothing wrong with the code fragment:

for(;0;)
printf("hello");
Nighter do I but who can guarantee that OP compiled this code? If you
look at indention it may seem that he has compiled something
completely different which correctly produces /hello/.

Seems like Richard Heathfield came to the same conclusion.

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
Sep 10 '06 #24
Keith Thompson wrote:
"Spidey" <am********@gmail.comwrites:
for(;0;)
printf("hello");

even the condition s wrong i get a hello printed on the screen
y s this happening
[snip]
I'm going to make a guess about what your problem is. You posted
this:

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

but your program really contains this:

for(;0;);
printf("hello");
No. His program does contain the code he has provided here (without the

semicolon at the end of for statement). That is actually a compiler bug
of
Turbo C++ 3.0. Its big time he got an upgrade from that compiler.

To OP(Spidey):
Turbo C++ has released a new compiler recently and its for free, so,
get an
upgrade and your code will work fine. Its available from
http://turboexplorer.com

Sep 10 '06 #25
Spidey wrote:
am using turbo c3 n it wont put up any warning.
and the code produced the hello output on my screen
Turbo C is known to be buggy.

Here is a program that exposes bugs on many compilers:

#include <stdio.h>

int main(void)
{
int arr[5];
printf("%d\n", (int)sizeof arr);
printf("%d\n", (int)sizeof &arr);
return 0;
}

The size of &arr should be the size of a pointer, probably just 2, 4 or
8 bytes. Many compilers miss the & and instead give the same value as
the size of arr, a multiple of 5.

Turbo C 2.01: 10, 10 (wrong)
Borland C/C++ 5.5: 20, 20 (wrong)
MS cl 13.10.3077: 20, 20 (wrong)
LCC-Win32 3.8: 20, 4 (right)
GCC 3.4.4: 20, 4 (right)

Not a good showing for Borland or Microsoft. Even when invoked in
"standard-conforming" mode, they fail this basic C89 test.

--
Simon.
Sep 10 '06 #26
Spidey wrote:
am using turbo c3 n it wont put up any warning.
and the code produced the hello output on my screen
C:\docs\prog\c>type for0.c
#include <stdio.h>

int main(void)
{
for(;0;)
printf("hello");

return 0;
}

C:\docs\prog\c>tcc for0.c
Turbo C Version 2.01 Copyright (c) 1987, 1988 Borland International
for0.c:
Warning for0.c 6: Unreachable code in function main
Turbo Link Version 2.0 Copyright (c) 1987, 1988 Borland International

Available memory 392912

C:\docs\prog\c>for0
As you can see, it does put up a warning, and it does not produce hello
on my screen. It works perfectly. This code does not expose a bug in the
compiler (but see my other article which gives an example that does
expose a bug).

You must not be compiling the same code as me.

--
Simon.
Sep 10 '06 #27
Spidey wrote:
am using turbo c3 n it wont put up any warning.
and the code produced the hello output on my screen
Get a decent compiler, and until you do, *please* don't post questions.
Igmar

Sep 10 '06 #28
Simon Biber wrote:
for(;0;)
printf("hello");
Would it kill you to use curly braces?
Sep 10 '06 #29
jmcgill wrote:
Simon Biber wrote:
> for(;0;)
printf("hello");

Would it kill you to use curly braces?
To what end? Add clutter?

Constructs like..

for (;0;) {
printf("world");
}

...add no special readability for me (except the indent of course).
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Sep 10 '06 #30
jmcgill said:
Simon Biber wrote:
> for(;0;)
printf("hello");

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.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 10 '06 #31
Richard Heathfield wrote:
jmcgill said:
Simon Biber wrote:
for(;0;)
printf("hello");
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.
Lack of braces is the first think I would notice
after an if or loop construct. And if I saw that
there weren't any braces I would look closely to
see which of the nearby statements are part of the
if or loop.

Having said that I tend to always use braces for
an if or loop construct which is followed by a
single statement if that single statement happens
to start with another if or loop construct. In the
complicated code above not using braces is just
playing with fire in a room where dynamite is
stored.
>
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.
Sep 10 '06 #32
"Scorpio" <av*******@gmail.comwrites:
Keith Thompson wrote:
>"Spidey" <am********@gmail.comwrites:
for(;0;)
printf("hello");

even the condition s wrong i get a hello printed on the screen
y s this happening
[snip]
>I'm going to make a guess about what your problem is. You posted
this:

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

but your program really contains this:

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

No. His program does contain the code he has provided here (without
the semicolon at the end of for statement). That is actually a
compiler bug of Turbo C++ 3.0. Its big time he got an upgrade from
that compiler.
How do you know? I'll take you word for it that Turbo C++ 3.0 has
such a bug, but the behavior the OP describes can be explained just as
easily by a semicolon after "for(;0;)".

(I'd still like to know why it occurred to the OP to write "for(;0;)"
in the first place.)

Until the OP posts an exact copy-and-paste of the code he actually
compiled, in the form of a complete program, we have no basis for
assuming what his code actually looks like. Until then, we're both
guessing.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 10 '06 #33
Joe Wright wrote:
jmcgill wrote:
>Simon Biber wrote:
>> for(;0;)
printf("hello");

Would it kill you to use curly braces?

To what end? Add clutter?

Constructs like..

for (;0;) {
printf("world");
}

..add no special readability for me (except the indent of course).
Whether or not it makes it more readable *for you* is not really the
issue.

Particularly when you post code for others to review, such as on
comp.lang.c, one would expect others to at least make an effort toward
clarity.

Brackets are not only proper syntax, they are also a good idea. They
are anything but "clutter."
Sep 10 '06 #34
jmcgill posted:
Simon Biber wrote:
> for(;0;)
printf("hello");

Would it kill you to use curly braces?

I only use compound statements when I want to compound multiple statements.

--

Frederick Gotham
Sep 10 '06 #35

Spidey wrote:
for(;0;)
^ - Perhaps you have a semicolon here at the end of this
line.
printf("hello");

even the condition s wrong i get a hello printed on the screen
y s this happening
Sep 11 '06 #36
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"

Sep 11 '06 #37

Scorpio wrote:
Keith Thompson wrote:
"Spidey" <am********@gmail.comwrites:
for(;0;)
printf("hello");
>
even the condition s wrong i get a hello printed on the screen
y s this happening
[snip]
I'm going to make a guess about what your problem is. You posted
this:

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

but your program really contains this:

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

No. His program does contain the code he has provided here (without the

semicolon at the end of for statement). That is actually a compiler bug
of
Turbo C++ 3.0. Its big time he got an upgrade from that compiler.

To OP(Spidey):
Turbo C++ has released a new compiler recently and its for free, so,
get an
upgrade and your code will work fine. Its available from
http://turboexplorer.com
Thanks Scopio, y was correct that was a compiler bug;

i tried another code ( dont call me stupid)

//for.c
#include <stdio.h>

int main( void)
{
int i=20;

for ( ; 5==6;) {
printf ( "Hello\n");
printf ( "%d\n", i);
}

return 0;
}

and i pressed ctrl+f9, and i got the following output

Hello
20

But when i compiled, i get the warning "Unreachable Code"
Here one thing i noticed is that for.exe is produced and when i tried
to execute it a message "Syntax error" is displayed............

In turboc3 when i press ctrl+f9 i am still getting the output.

"Any way, its a compiler bug" Thanks scorpio

Sep 11 '06 #38
jmcgill wrote:
Brackets are not only proper syntax, they are also a good idea. They
are anything but "clutter."
Opinions differ.

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

--
Chris "appendix-free zone" Dollin
"Reaching out for mirrors hidden in the web." - Renaissance, /Running Hard/

Sep 11 '06 #39
Keith Thompson wrote:
"Scorpio" <av*******@gmail.comwrites:
Keith Thompson wrote:
"Spidey" <am********@gmail.comwrites:
for(;0;)
printf("hello");

even the condition s wrong i get a hello printed on the screen
y s this happening
[snip]
I'm going to make a guess about what your problem is. You posted
this:

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

but your program really contains this:

for(;0;);
printf("hello");
No. His program does contain the code he has provided here (without
the semicolon at the end of for statement). That is actually a
compiler bug of Turbo C++ 3.0. Its big time he got an upgrade from
that compiler.

How do you know? I'll take you word for it that Turbo C++ 3.0 has
such a bug, but the behavior the OP describes can be explained just as
easily by a semicolon after "for(;0;)".
Yes, I do agree with you that the OP might have made a typo while
posting and might actually have a semicolon after for loop. But in
this case, since the OP has mentioned that he is using Turbo C++ 3.0
and I was aware of this particuar bug in Turbo C++, it was quite
obvious for me that OP has encountered this bug in the compiler and its
not actually a typo.

Sep 11 '06 #40
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>Gv th mn a bnn!
>Give the man a bunny?
Bunion?

-- Richard
Sep 11 '06 #41
Really?
I get nothing.^_^

Sep 11 '06 #42

Spidey wrote:
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.

Sep 11 '06 #43
Simon Biber <ne**@ralmin.ccwrote:
#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.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Sep 11 '06 #44
"ar******@gmail.com" <ar******@gmail.comwrote:
Really?
I get nothing.^_^
No wonder, if you post without context.

Richard
Sep 11 '06 #45

Spidey wrote:
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.

Sep 11 '06 #46

In article <11**********************@m79g2000cwm.googlegroups .com>, "Spiros Bousbouras" <sp****@gmail.comwrites:
Keith Thompson wrote:
Richard Heathfield <in*****@invalid.invalidwrites:
[...]
Gv th mn a bnn!
Give the man a bunny?

Banana !
And here I was sure it was "bunion".

--
Michael Wojcik mi************@microfocus.com
Sep 11 '06 #47
Chris Dollin wrote:
jmcgill wrote:
>Brackets are not only proper syntax, they are also a good idea. They
are anything but "clutter."

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.
Sep 11 '06 #48
Richard Heathfield wrote:
jmcgill said:
Simon Biber wrote:
for(;0;)
printf("hello");
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.

Sep 12 '06 #49
jmcgill wrote:
Chris Dollin wrote:
>jmcgill wrote:
>>Brackets are not only proper syntax, they are also a good idea. They
are anything but "clutter."

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.
Well, that's a relief.

Urm ... and?

--
Chris "don't know where mine is" Dollin
Meaning precedes definition.

Sep 12 '06 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.