Trash Talk - Trying to learn to code better Pests - Sun Jun 20, 2004 11:50 pm Post subject: Trying to learn to code better
Hi, I've really been trying to code better recently, but I feel I'm not useing MSVC6 correctly or to its fullest potential. Could someone direct me where I could learn more about it or someone teach me? For example, the only things I really ever do is run the program, and fix any bugs that come up. I'm sure theres better ways out there then to guess and check whats wrong and how to fix, ect. Like, I hear talk of break points and all the good things, but I don't know how to use them.
CypherJF - Mon Jun 21, 2004 12:27 am Post subject:
Not really, other than learn the language well; then while learning hopefully you'll learn how to debug well.
www.cplusplus.comMr Ekted - Mon Jun 21, 2004 12:36 am Post subject:
Write a simple Win32 console app, and put in a bug on purpose. Then start playing with the debugger to see how easy it is to see what's going on knowing where the bug is. Here's a small app with 2 bugs. I'll let you figure out what they are.
void main ()
{
char *p = "this is a string";
char *q;
char buf[64];
q = buf;
while (p)
*q++ = *p++;
printf("The buffer = %s\n", buf);
}
Play around with the debug stuff after this crashes. If you need more direction, reply here where you are and I'll help some more.
50% Packetloss - Mon Jun 21, 2004 4:05 am Post subject:
Pick up a book, browse through the stuff that you think you know and check out anything that looks new. Maybe sign up for a class to teach you a lower level language.
I believe i got the answer, translated it into hex so i didnt spoil it for anyone else
23696E636C756465203C737464696F2E683ED0A0696E74206D61696E2829D0A07768696C6520282A702920D0A072657475726E20303B00
http://nickciske.com/tools/hex.phpCypherJF - Mon Jun 21, 2004 4:07 am Post subject:
Good idea Dustpuppy - Mon Jun 21, 2004 6:10 am Post subject:
I'd say one of your bugs is correct but the others are pretty irrelevant. Besides Ekted said there were 2 bugs and you gave 3
I think the remaining bug will be fairly obvious if you run it after finding the first one.
Mine GO BOOM - Mon Jun 21, 2004 11:18 am Post subject:
Main does not need to be an int. And if it does, you are not required to have a return 0 at the end, as it is implied. These are somewhat recent changes, but I read about them somewhere when someone whined that GCC no longer prints warnings or errors or something whenever they don't have the return 0 statement.
I would google more for answers, but the main function is special, and having it be void, or int without a return statement, is perfectly legitimate.
EDIT: Bah, I'm not one to go without googling for answers. Here, read this.
Mr Ekted - Mon Jun 21, 2004 3:01 pm Post subject:
50% you missed one of the real bugs... Bak - Mon Jun 21, 2004 3:05 pm Post subject:
23696E636C7564652022737464696F2E6822D0A0D0A0766F6964206D6169
6E20282920D0A07B20D0A09063686172202A70203D20227468697320697
3206120737472696E67223B20D0A09063686172202A713B20D0A09063686
17220206275665B36345D3B20D0A0D0A09071203D206275663B20D0A0D
0A0907768696C6520282A7029D0A0907BD0A090902A712B2B203D202A7
02B2B3B20D0A0907DD0A0902A71203D20303BD0A0D0A0907072696E746
6282254686520627566666572203D2025735C6E222C20627566293B20D0
A07D00
http://nickciske.com/tools/hex.phpMr Ekted - Mon Jun 21, 2004 4:42 pm Post subject:
Good Cyan~Fire - Tue Jun 22, 2004 1:27 pm Post subject:
OK, I got the "first" bug just by looking at it, but not the second. I seem to think for some reason that arrays are automatically zeroed?
Mr Ekted - Tue Jun 22, 2004 3:12 pm Post subject:
Nothing happens without code.
In VC debugger, all uninitialized stack space and allocated space are filled with specific bytes, so if you have a bug and notice this particular byte, it's a clue that something is uninitialized. Freed memory is filled with a different byte, so it's easier to tell when you are still referencing freed memory.