Skip to main content
gamedev.net
🔒 Locked

Stupid C/C++ errors - valid syntax, incorrect effect

Started by intransigent-seal 5 replies 750+ views
Original Post
intransigent-seal
intransigent-seal
What stupid bugs have you had in your programs that were caused by C or C++ letting you write code that does nothing at all, or something completely stupid? I'll start:
  
// the cliche

if (foo = bar)
  qux();
// should be ==, not =


// the not-quite-so-cliche sibling

foo == bar;
// should be =, not ==, this code is valid syntax, but does nothing


while (foo);
{
  bar();
  qux();
}
// there shouldn't be a semi-colon after the condition of the while loop

// This just executes bar() and qux() once, whatever foo is  
[edit: formatting] JohnB [edited by - JohnBSmall on May 10, 2003 11:39:40 PM]
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Xtremehobo
Xtremehobo

  
if (foo==bar) {
qux();
..rest of program
//sometimes I forget to close off an if statement with the }




-----
I 4M T3H SIGN4TUR3 FR0M H311x0res!
pixelwrench.com | [email="matt[nospam]@pixelwrench[nospam]com"]email[/email] lethalhamster: gamedev keeps taking my money, but im too lazy to not let them
Tron3k
Tron3k
I usually put in this:

if (foo == bar) {
}

and then add the code in the middle.
“[The clergy] believe that any portion of power confided to me, will be exerted in opposition to their schemes. And they believe rightly: for I have sworn upon the altar of God, eternal hostility against every form of tyranny over the mind of man” - Thomas Jefferson
987th Yak
987th Yak

  
switch(foo); //ARGGG!!!

{
case thing:
stuff();
break;

case thing2:
stuff2();
break;
}


I hates it when I do that.....

It''s way harder than you''d think to pick a something good for these....
-----------------------------------------------------------PLEASE don't comment on the pointlessness of this post!!
Dredge-Master
Dredge-Master
Ansi C and Borland syntax

(only found out recently with gdarena)

if(dw.buttons&JOY_BUTTON1 && dw.buttons&JOY_BUTTON2)

works fine


under msvc6 (haven''t changed any project settings, so for all I know the default may NOT be ansi C)
if(dw.buttons&JOY_BUTTON1 && dw.buttons&JOY_BUTTON2)

fails
have to use
if(dw.buttons&JOY_BUTTON1 && (dw.buttons&JOY_BUTTON2))

as the order of opps doesn''t follow ansi C.


But hey, I guess it makes it easier to read
Beer - the love catalystgood ol' homepage
bastardos
bastardos

Okay, compiler-bashing it is.

void Function (char * something)
{
//blah blah
*pointer++ = something [index];
//blah blah
}

Used to work fine, ''til I switched to Dev-C++ (MingW).

void Function (char * something)
{
char * somethingelse = something;
//blah blah
*pointer++ = somethingelse [index];
//blah blah
}

Worked again.

-bas
.basprintf ( "And for the %dth time, I'm not American!", ++lIdiots );My homepage

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.