Ancient_Hacker wrote:
Please provide context. You've been here long enough to know it is expected.
The post you were replying to said
| It will not run. This is fine.
| main()
| {
| unsigned int i;
| for(i=1;i>-2;i--)
| printf("c aptitude");
| }
|
| but in the same code if i ll make unsigned int as short unsigned int
| then it will run for an infinite loop.
| what is the reason?
| thanks.
well in general you're hoping that an unsigned int will somehow count
down to -2.
Unlikely on the face of it, but you say it works fine.
That may be, but only due to a binary coincidence.
Or it could be because it does exactly what the C standard requires it
does. Look up the usual arithmetic promotions.
If you change it to a short, then it may seem to wrap around funny,
like from 2, 1, 0, -65535.
I somehow doubt it will wrap from 0 to -65535 under any conditions ;-)
In any case, if you listen to the compiler warnings, you wouldnt have
this problem.
Styrongly suggest yuou use -warn=99 or whatever. "C" is hard enough--
you can't afford to ignore the few warnigns the compiler can put out.
This advice is good. For details of how to get a compiler to produce
decent warnings you are best asking on a group dedicated to your
compiler. Or reading the manual/help, of course!
--
Flash Gordon
Still sigless on this computer