The C language is terse and expressive. There are few restrictions to keep the user from blundering. In this topic we will find out the pitfalls and try to find out what should be done to run a C program.
I will begin with the basic mistake programmers do (Obviosly due to there work-load) and its consequence.
QUOTE
= is not ==
Programming languages derived from Algol, such as Pascal and Ada, use := for assignment and = for comparison. C, on the other hand, uses = for assignment and == for comparison. This is because assignment is more frequent than comparison, so the more common meaning is given to the shorter symbol.
Moreover, C treats assignment as an operator, so that multiple assignments (such as a=b=c) can be written easily and assignments can be embedded in larger expressions.
This convenience causes a potential problem: one can inadvertently write an assignment where one intended a comparison. Thus, this statement, which looks like it is checking whether x is equal to y:
CODE
if (x = y) foo();
Actually sets x to the value of y and then checks whether that value is nonzero. Or consider the following loop that is intended to skip blanks, tabs, and newlines in a file:
CODE
while (c == ’ ’ || c = ’\t’ || c == ’\n’) c = getc (f);
The programmer mistakenly used = instead of == in the comparison with ’\t’. This ‘‘comparison’’ actually assigns ’\t’ to c and compares the (new) value of c to zero. Since ’\t’ is not zero, the ‘‘comparison’’ will always be true, so the loop will eat the entire file. What it does after that depends on whether the particular implementation allows a program to keep reading after it has reached end of file. If it does, the loop will run forever.
Some C compilers try to help the user by giving a warning message for conditions of the form e1 = e2. To avoid warning messages from such compilers, when you want to assign a value to a variable and then check whether the variable is zero, consider making the comparison explicit. In other words, instead of:
CODE
if (x = y) foo();
write:
CODE
if ((x = y) != 0) foo();
This will also help make your intentions plain.
It is easy to miss an inadvertent substitution of = for == because so many other languages use = for comparison. It is also easy to interchange & and &&, or | and ||, especially because the & and | operators in C are different from their counterparts in some other languages.
Multi-character Tokens
Some C tokens, such as /, *, and =, are only one character long. Other C tokens, such as /* and ==, and identifiers, are several characters long. When the C compiler encounters a / followed by an *, it must be able to decide whether to treat these two characters as two separate tokens or as one single token. The C reference manual tells how to decide:
‘‘If the input stream has been parsed into tokens up to a given character, the next token is taken to include the longest string of characters which could possibly constitute a token.’’
Thus, if a / is the first character of a token, and the / is immediately followed by a *, the two characters begin a comment, regardless of any other context.
The following statement looks like it sets y to the value of x divided by the value pointed to by p:
CODE
y = x/*p /* p points at the divisor */;
In fact, /* begins a comment, so the compiler will simply gobble up the program text until the */ appears. In other words, the statement just sets y to the value of x and doesn’t even look at p. Rewriting this statement as
CODE
y = x / *p /* p points at the divisor */;
or even
CODE
y = x/(*p) /* p points at the divisor */;
would cause it to do the division the comment suggests.
This sort of near-ambiguity can cause trouble in other contexts. For example, older versions of C use =+ to mean what present versions mean by +=. Such a compiler will treat
a=-1; as meaning the same thing as
a =- 1; or
a = a - 1; This will surprise a programmer who intended
a = -1; On the other hand, compilers for these older versions of C would interpret
a=/*b; as
a =/ * b ; even though the /* looks like a comment.
Before posting anything more I would like to know whether anybody is interested in this topic or not ?
Case 1. I believe that to many people today have just given up on school and education. For
instance many people i know just don't try. They are perfectly capable of doing well, but they
have decided not to work. A lot of these people have given up i would say around 4-6th grade and if
it isn't dealt with quickly it becomes habit and then everything gets harder as teachers start
to label these kids and then they just get shunned from proper education. In the USA now it is very
hard to get a good job without an education at least through high school. These p....
Well I'm a 3rd Degree Solitary High Priestess Of Witchcraft, And I have to say I am upset that I
Have Not had the good fortune to meet another Witch on here yet. So I thought I would start this
thread to make my brothers & sisters fly out of the besom closet.... I kind of feel like we're
all playing cyber hide & seek with eachother... Come out come out wherever you are:)....
Welcome to "Hard Decision of the Week!" This is an endeavour I want to try to keep up every
week. It's about hard decisions and determining what you really value. Each week I'll post
an imaginary scenario where you have to make a decision. (And yes, the decision is a pretty hard
one.) You can discuss the decision itself, or what it values. (And please don't flame each
other, otherwise I'll get into trouble for starting the topic.) Here's this week's
decision, one that only got about 6 responses in Yahoo Answers, where I originally posted i....
Hey, I am 18 and I already have a collection of 150 poems, If I receive a positive response to this
post, I'll be sure to post my poems regularly in this topic. I really need honest reviews for my
poems from people who do not know me personally. I am considering publishing my booklet this coming
year and I could use all the help I can get thank you....
Location Based Alarms (LBS) Location Based services are applications which provide software
soutions which are location sensitive. Location Based Alert is a very useful kind of Location
Based Service in which alerts can be set based on your location but not based on your time. So that
when you travel long distances, you need not set alarm in your mobile phone based on your expected
time to reach, Instead you can set alarm based on your destination and need not worry about the time
delays in your travel. Location Based Services are used the most only in mobile ....
I was looking for a thread on digital cameras but could not seem to find 1. So I did a search, and
still no related threads. I was wondering whether there is any place we can discuss digital
cameras? If we don't, is it possible to create a couple of forums for it? Because it would
help people like me who are looking to purchase a new camera but don't know the flaws of each
model/brand. What do you say?....
Hey everyone the NFL Draft is going on right now and here is the place to discuss it! I will
post up the new pick every time it is drafted (until I have to go). And we can also discuss the
draft here! Start the talk! 1 1 Oakland |Russell, JaMarcus QB 2 2 Detroit |Johnson,
Calvin WR 3 3 Cleveland |Thomas, Joe OT 4 4 Tampa Bay |Adams, Gaines DE 5 5 Arizona
|Brown, Levi OT e 6 6 Washington |Landry, LaRon FS 7 7 Minnesota |Peterson, Adrian
8 8 Atlanta (from Houston) |Anderson, Jamaal DE 9 9 Miami |Ginn Jr., Ted WR 10 10 Houston (from
A....
The GTA games always have been great games. I've played them all and i've liked them more
than any other game. I was very exites when i knew about the coming out of GTA IV. At the same
time very sad because it wouldn't be a pc version. What are the reasons of Rockstar Games for
not publishing a pc version too?! GTA games are the most favourites of Pc gamers. I think they
have made a very big mistake for not publishing GTA IV in PC too.....
China - a country that has been bullied for far too long. It has once been a nation of great freedom
and national pride with many great inventions including gunpowder, compasses, fire arrows,
chopsticks, paper, kites, wheelbarrow, etc. Surely, a country with such great inventions would not
be so weak? Yet, they did become weak due to the rise of the communist party; it has restricted
great inventors from inventing; great authors to write; great men to think. The western countries
see communism as a horrible way to treat the citizens of the state; a horrible way make a co....
Hi This is Sekhar. Please post replies about ur experiences in love including your contact details.
I or other members may solve your problems or share your moments. +91 9933026667
sekhargreen@gmail.com Topic moved to appropriate subforum ....
Well This Very Very Interesting Topic So Tell Ur Thoughts On This. Well Friendz Wht Do U Think Y Do
people Spam On Websites 1)Do They Like To Have Fun Spaming On Websites 2) They Want Publicity Of
There Website 3) They Want People Of The Other Website To Come On there Site 4) They Want To Rune
The High Priority Of The Other Website 5) If Not These Tell Ur Own Thoughts. Thanx keep Posting Ur
Thoughts As This Is Very Interesting Topic . Never Evert Do Spam On The Websites Otherwise
U Will Be Banned On That Website For Ever Thanx. ....
lets discuss the psp homebrew here. heres a few sites QUOTE www.noobz.eu www.pspupdates.com
www.pspbrew.com www.pspvault.com and www.download.qj.net if wana know more about psp brew ask
me or visit the above sites....
i'm a fan of fantasy books, real ones not lame ones like harry pothead. who else enjoys these
kinds of books and what authors/titles do you enjoy? I've recently been reading the sword of
truth series by terry goodkind which i have been enjoying quite a bit, and the shannara and the
landover series by terry brooks (who also wrote the novelizations of hook and star wars ep1)....
Hey people out there........u must b tired of talkin about games on PC or other
consoles...........So lets talk about one othe best members of Nokia Family- NGAGE Any one
having nething to say about this ....is welcome.......so lets get started...... Fixed BB code. ....
This thread is the Discuss your OS Game! The "Discuss your OS" game is a remake of the +/=/-
game some forums do to rate people on their ideas. Basically, this is a chance for you to discuss
your opinions on any Operating System you use. The way you do this is simple: 1. Click the "Post
Reply Button" 2. Put these symbols onto four separate lines: OS: + = - 3. Where it says OS: , you
type the Operating System you use (Example: Windows XP). Then on each other line write your opinions
about that System. Next to the + write something(s) you like the most, next to the....
I have this really stupid science teacher. He always reapeats himself but manages to never explain
anything! He also does this thing where he looks at his watch whenever we're talking but
never actually SAYS "be quiet" so we never know he's trying to get our attentin unless we feel
like looking at his ugly face. his head is really small and ugly....
I was watching a television program a few nights ago called 'Beyond Tommorow'. They had a
segment on about a engeneering breakthrough. A university in North America have discovered that a
unique sea eel (Lamp Eel) has INDIVIDUAL nerve centres in every part of it's spinal cord. The
university started to study the nerve waves and record it, transfer it to digital data and then send
it into an artificial robot. These nerve waves made this robot walk in a human-like way. Soon this
university plans to make two microchips to implant in the broken spinal cord of a....
there has been so much discussion about final fantasy and kingdom hearts. Why is Sqaure Enix pushing
back there games that are the best? It's just not fair!!!!!!!
/unsure.gif' border='0' style='vertical-align:middle' alt='unsure.gif' /> ....
I don't know about you guys, but my internet is sort of awry. When it goes it, it can stay out
for a few days - enough time for my hosting to expire. I think people would feel more comfortable
posting in the forums if they had a certain quota each month. Many people have busy lives with
families and work that doesn't give them the choice to sit at a computer whenever they want,
unless, of course, you want them to post at work when they should be working. Maybe, post 5 things a
month? Something more relaxed. A community is one that should form without being forced....
Looking for c, pitfalls, discuss, loopholes, c
Searching Video's for c, pitfalls, discuss, loopholes, c
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE
forum, Create your own topics, Ask Questions, track topics, setup
subscriptions & notifications and Get a Free Website w/ Email and FTP.