473,396 Members | 1,871 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,396 software developers and data experts.

what is the reason ?

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.

Aug 4 '06 #1
7 1471
co******@gmail.com wrote:
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?
Turn on compiler warnings and you can probably figure this out yourself.
Igmar
Aug 4 '06 #2


co******@gmail.com wrote On 08/04/06 10:09,:
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?
The "usual arithmetic conversions."

--
Er*********@sun.com

Aug 4 '06 #3
Sorry Man
I dont know how turn ON this?

Aug 4 '06 #4
co******@gmail.com wrote:
Sorry Man
I dont know how turn ON this?
"Consult your documentation."

For example, if I was using Microsoft VC, I would consult
http://msdn.microsoft.com or the local help files. For GCC, similar
help is available.

See also, <http://catb.org/~esr/faqs/smart-questions.html>
Aug 4 '06 #5
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.
If you change it to a short, then it may seem to wrap around funny,
like from 2, 1, 0, -65535.

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.

Aug 4 '06 #6
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
Aug 4 '06 #7
Igmar Palsenberg wrote:
co******@gmail.com wrote:
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?

Turn on compiler warnings and you can probably figure this out yourself.
Despite being riddled with issues, there is nothing in the code that
requires a
C90 compiler to issue a diagnostic. I know of at least 2 compilers that
woundn't
issue the particular desired warning, no matter how high you turned
them up.

IIRC, the gcc diagnostic warns about the cause, but doesn't elaborate
on the
issue. So, given the demonstration of coding so far, I seriously doubt
that the
OP will figure it out.

Fortunately, the problem (actually its mirror) is covered in the FAQ...

http://www.c-faq.com/expr/preservingrules.html

--
Peter

Aug 5 '06 #8

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
83
by: rahul8143 | last post by:
hello, what is difference between sizeof("abcd") and strlen("abcd")? why both functions gives different output when applied to same string "abcd". I tried following example for that. #include...
11
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
44
by: Viken Karaguesian | last post by:
Hello all, On occasion I want to open hyperlinks (images, etc.) in a new window. In the past, I've used target="_blank" to open the link in a new window. However, using the "target" attribute...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.