Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

Reply
 
Thread Tools Display Modes
  #1  
Old 11-22-2002, 02:34 AM
neotokyo
Hill Giant
 
Join Date: Oct 2002
Posts: 118
Default coding competition

for(uint32 i=0; i!=max_door_type;i++)
{
const Door* door = GetDoorDBID(i);
if(door == 0 || door->db_id == 0 || strcasecmp(door->zone_name, zone_name))
continue;
if(door->door_id == door_id && strcasecmp(door->zone_name, zone_name) == 0)
return door;
}

whats wrong with these few lines of code ...?
winner gets a free ticket to new delhi, india.

(and btw, this is not to diss anybody, but perhaps people will learn to code if we get the most commonly errors communicated)
*edit: feel free to post my errors too, if you find some.*
Reply With Quote
  #2  
Old 11-22-2002, 03:06 AM
Lurker_005
Demi-God
 
Join Date: Jan 2002
Location: Tourist town USA
Posts: 1,671
Default

Ok, not a coder, but I like to play with it anyhow :p

Shouldn't it be checking for true?
if(door->door_id == door_id && strcasecmp(door->zone_name, zone_name) == 1)

and why is it running thru door types and not door ID's?
for(uint32 i=0; i!=max_door_type;i++)
__________________
Please read the forum rules and look at reacent messages before posting.
Reply With Quote
  #3  
Old 11-22-2002, 03:32 AM
neotokyo
Hill Giant
 
Join Date: Oct 2002
Posts: 118
Default

close, but no cigar

string-compare functions always return 0 if strings are equal - so that is ok.
max_door_type is a bad name, but other than that its used correctly.
Reply With Quote
  #4  
Old 11-22-2002, 03:54 AM
Bardboy
Hill Giant
 
Join Date: Feb 2002
Location: Area 51
Posts: 157
Default

Maybe I can answer that next semester, when I take C Programming I class.
__________________
They say verbal insults hurt more then physical pain. They are of course wrong, as you will soon find out when I put this toasting fork in your head.

Blackadder
Reply With Quote
  #5  
Old 11-22-2002, 04:11 AM
Trumpcard
Demi-God
 
Join Date: Jan 2002
Location: Charlotte, NC
Posts: 2,614
Default

This might not be the answer youre looking for, but using != max is a bit dangerous.
If max gets set to a value other than an integer, or the comparison fails to catch the exit condition, which might be easy to do, this is an infinite loop.

Safer practice would be <=max_type
__________________
Quitters never win, and winners never quit, but those who never win and never quit are idiots.
Reply With Quote
  #6  
Old 11-22-2002, 04:26 AM
neotokyo
Hill Giant
 
Join Date: Oct 2002
Posts: 118
Default

trump: right on both accounts. it is much safer, and it isnt the answer i am looking for
Reply With Quote
  #7  
Old 11-22-2002, 04:36 AM
kathgar
Discordant
 
Join Date: May 2002
Posts: 434
Default

Code:
/*guessing*/Door * GetDoorByDoorID(const *zone_name,uint32 door_id)
{/*god I hate editing code this way*/
for(uint32 i=0; i!=max_door_type;i++)
{
const Door* door = GetDoorDBID(i);
/*if door is undefined you try to dereference this=bad+crash */
//if(door == 0 || door->db_id == 0 || strcasecmp(door->zone_name, zone_name))
if(door){if(door->db_id==door_id && strcasecmp(door->zone_name, zone_name)==0)
return door;//continue;
//if(door->door_id == door_id/*this doesnt' exist*/ && strcasecmp(door->zone_name, zone_name) == 0)
//return door;}
} 
return NULL;//if we don't find it
}
clean block
Code:
Door * GetDoorByDoorID(const *zone_name,uint32 door_id)
{/*god I hate editing code this way*/
         for(uint32 i=0; i!=max_door_type;i++)
         {
                  const Door* door = GetDoorDBID(i);
                  if(door)
                  {
                        if(door->db_id==door_id && strcasecmp(door->zone_name, zone_name)==0)
                               return door;
                  }
         } 
         return NULL;//if we don't find it
}
Neo: read the post on the dev board about looking for new devs, then you get CVS access <3
__________________
++[>++++++<-]>[<++++++>-]<.>++++[>+++++<-]>[<
+++++>-]<+.+++++++..+++.>>+++++[<++++++>-]<+
+.<<+++++++++++++++.>.+++.------.--------.>+.
Reply With Quote
  #8  
Old 11-22-2002, 04:46 AM
neotokyo
Hill Giant
 
Join Date: Oct 2002
Posts: 118
Default

do i get a cool board title and avatar then? )

and the '@' in irc?

and a trailer and a cook and daily massage?

btw. kath: the code is still wrong but much better then before
Reply With Quote
  #9  
Old 11-22-2002, 05:23 AM
Trumpcard
Demi-God
 
Join Date: Jan 2002
Location: Charlotte, NC
Posts: 2,614
Default

Yep.. And you can boot me out of IRC when I post too many crappy code changes!
__________________
Quitters never win, and winners never quit, but those who never win and never quit are idiots.
Reply With Quote
  #10  
Old 11-22-2002, 05:27 AM
kathgar
Discordant
 
Join Date: May 2002
Posts: 434
Default

anyone can change their avatar and title... and you would get probably %(halfop.. topic kick ban, just not halfop or op others)
__________________
++[>++++++<-]>[<++++++>-]<.>++++[>+++++<-]>[<
+++++>-]<+.+++++++..+++.>>+++++[<++++++>-]<+
+.<<+++++++++++++++.>.+++.------.--------.>+.
Reply With Quote
  #11  
Old 11-22-2002, 05:39 AM
kathgar
Discordant
 
Join Date: May 2002
Posts: 434
Default

Code:
/*guessing*/Door * GetDoorByDoorID(const *zone_name,uint32 door_id)
{/*god I hate editing code this way*/
for(uint32 i=0; i!=max_door_type;i++)
{
const Door* door = GetDoorDBID(i);
/*if door is undefined you try to dereference this=bad+crash */
//if(door == 0 || door->db_id == 0 || strcasecmp(door->zone_name, zone_name))
if(door){if(door->db_id==door_id && strcasecmp(door->zone_name, zone_name)==0)
return door;//continue;
//if(door->door_id == door_id/*this doesnt' exist*/ && strcasecmp(door->zone_name, zone_name) == 0)
//return door;}
} 
return NULL;//if we don't find it
}
clean block
Code:
Door * GetDoorByDoorID(const *zone_name,uint32 door_id)
{/*god I hate editing code this way*/
         Door* door = NULL;
         for(uint32 i=0; i<max_door_type;i++)
         {
                  door = GetDoorDBID(i);
                  if(door)
                  {
                        if(door->db_id==door_id && strcasecmp(door->zone_name, zone_name)==0)
                               return door;
                  }
         } 
         return NULL;//if we don't find it
}
Thats all I see at the moment.. now i'll get some breakfast.. er lunch.. wahtever
__________________
++[>++++++<-]>[<++++++>-]<.>++++[>+++++<-]>[<
+++++>-]<+.+++++++..+++.>>+++++[<++++++>-]<+
+.<<+++++++++++++++.>.+++.------.--------.>+.
Reply With Quote
  #12  
Old 11-22-2002, 06:53 AM
alkrun
Sarnak
 
Join Date: Jan 2002
Posts: 66
Default

for(uint32 i=0; i <= max_door_type; i++)
{
Door* door = GetDoorDBID(i);
if(door == NULL)
continue;

if(door->db_id == 0 || strcasecmp(door->zone_name, zone_name))
continue;

if(door->door_id == door_id && strcasecmp(door->zone_name, zone_name) == 0)
return door;
}



My personal preference... I hate using 0 in the place of NULL. it's one of my biggest complaints about the emu sourcecode. Since you all don't use hungarian, sometimes it's not directly obvious if a variable is an id or a pointer. If you see this:

if(door == 0)

door could be either. If you see this:

if(door = NULL)

then it's pretty obvious that it's a pointer.

Another of my pointer issues is testing for null in the same conditional as you use to test for a member's value like the original code was testing door and then the door's database id. I prefer to see them split up like I have them. Again, it's a style thing, but with so many people working on the same code, it's easy to get someone to add a condition to your statement and make a mistake.
Reply With Quote
  #13  
Old 11-22-2002, 07:18 AM
kathgar
Discordant
 
Join Date: May 2002
Posts: 434
Default

Not just a style thing, if you test if the pointer is null and dereference it in the same if it tries to dereference if it is null.. which is quite bad
__________________
++[>++++++<-]>[<++++++>-]<.>++++[>+++++<-]>[<
+++++>-]<+.+++++++..+++.>>+++++[<++++++>-]<+
+.<<+++++++++++++++.>.+++.------.--------.>+.
Reply With Quote
  #14  
Old 11-22-2002, 11:58 PM
neotokyo
Hill Giant
 
Join Date: Oct 2002
Posts: 118
Default

Quote:
Originally Posted by kathgar
Code:
Door * GetDoorByDoorID(const *zone_name,uint32 door_id)
{/*god I hate editing code this way*/
         Door* door = NULL;
         for(uint32 i=0; i<max_door_type;i++)
         {
                  door = GetDoorDBID(i);
                  if(door)
                  {
                        if(door->db_id==door_id && strcasecmp(door->zone_name, zone_name)==0)
                               return door;
                  }
         } 
         return NULL;//if we don't find it
}
we have a winner )

the problem was:
Code:
Door* door = GetDoorDBID(i);

since the for-loop doesnt leave the scope, the variable door is intialized using GetDoorDBID(i) (which in this case i == 0), and then never again touched. so all you do is that you run the loop thru from i=0 to i=max_door_type, but with always the same door.


take care,
neo
Reply With Quote
  #15  
Old 11-23-2002, 08:28 AM
Baron Sprite's Avatar
Baron Sprite
Dragon
 
Join Date: Jan 2002
Posts: 708
Default

% is sexy
oh forgot:
Code:
#include <iostream.h>

int main()
{
    std::cout << "Hello, world!\n";
}
__________________
Waking up in the morgue is pretty harsh, but it beats being dead.
Begun, this irc stat war has.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 06:06 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3