• Welcome to Valhalla Legends Archive.
 

[C++] Header file organization.

Started by Sorc.Polgara, December 30, 2004, 09:19 PM

Previous topic - Next topic

Sorc.Polgara

Ok, here I made a little list of the source files (.cpp) and the header files that each need to be included.  Some are ones that I made and others are ones that are built-in or w/e.

Quote
Dependencies

packetbuffer.cpp
- windows.h
- iostream.h
- malloc.h

packetdebuffer.cpp
- windows.h
- iostream.h
- malloc.h

main.cpp
- winsock2.h
- windows.h
- stdlib.h
- iostream.h
- malloc.h
- SendBNCS.h
- SendBNLS.h
- RecvBNCS.h
- RecvBNLS.h
- packetdefs.h

RecvBNCS.cpp
- RecvBNCS.h
- windows.h
- iostream.h
- malloc.h
- packetbuffer.h
- packetdebuffer.h
- packetdefs.h

RecvBNLS.cpp
- RecvBNLS.h
- windows.h
- iostream.h
- malloc.h
- packetbuffer.h
- packetdebuffer.h
- packetdefs.h

SendBNCS.cpp
- SendBNCS.h
- windows.h
- iostream.h
- malloc.h
- packetbuffer.h
- packetdefs.h

SendBNLS.cpp
- SendBNLS.h
- windows.h
- iostream.h
- malloc.h
- packetbuffer.h
- packetdefs.h

Many of the source share multiple header files in common.  An example would be the malloc.h, windows.h,  iostream.h,  packetdefs.h, and packetbuffer.h.

I get compiling errors when I try to include a header files in multiple source files.  Why exactly isn't it a good idea to make just a header file that includes header files that are share in common... it works when I compile it, yet some of you say it isn't something some of you would do...

And I have put the #ifndef code that mynd suggested.  I actually had it there before it was suggested because a C++ book I have put it there.

MyndFyre

Having header files really has nothing to do with object-oriented programming...

Also, make sure to use:


#pragma once

or

#ifndef PACKETBUFFER_H
#define PACKETBUFFER_H          // for example
...... (c code)

#endif

QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Kp

Don't use #pragma once.  Excerpt from GCC manual on why #pragma should not be used:

Quote2. There is no telling what the same #pragma might mean in another compiler.

These two reasons applied to almost any application that might have been proposed for #pragma. It was basically a mistake to use #pragma for anything.

Also, I find it to be very disruptive to lay out my header files in the fashion you have described, as it really defeats the point of a dependency list if all the headers are included in every source file.  Then changing any header forces everything to be recompiled, even if the change had no relation to some of the afflicted files.  For instance, if you change the parameter list to your bot constructor, that doesn't affect the packetbuffer code - but your layout will force the packetbuffer to be rebuilt anyway.  Although it requires a bit more thought, I find it to be more convenient to have each source file include headers that it needs.  Of course, if packetbuffer.h makes no sense without windows.h included before it, there's a case for having packetbuffer.h include windows.h, since the compile is guaranteed to fail when windows.h isn't included.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Sorc.Polgara

Quote from: MyndFyre on December 30, 2004, 10:43 PM
Having header files really has nothing to do with object-oriented programming...

Also, make sure to use:


#pragma once

or

#ifndef PACKETBUFFER_H
#define PACKETBUFFER_H          // for example
...... (c code)

#endif

ok.


Hmmmm while I'm here, I need to ask another question.

Back when I had made my VB Bot I had the login sequence all done.  However since then I've lost all my notes, pseudo code, programs that I did due to harddrive failure. That said, I have most of the sequence but the only thing that I can't remember is where I put the BNLS_CHOOSENLSREVISION (0x0D) in it.

I can't seem to place it.  Would this packet cause SID_AUTH_CHECK (0x51) to respond with an "0x101:  Invalid version"?

MyndFyre

Quote from: Sorc.Polgara on December 31, 2004, 11:42 AM
Quote from: MyndFyre on December 30, 2004, 10:43 PM
Having header files really has nothing to do with object-oriented programming...

Also, make sure to use:


#pragma once

or

#ifndef PACKETBUFFER_H
#define PACKETBUFFER_H          // for example
...... (c code)

#endif

ok.


Hmmmm while I'm here, I need to ask another question.

Back when I had made my VB Bot I had the login sequence all done.  However since then I've lost all my notes, pseudo code, programs that I did due to harddrive failure. That said, I have most of the sequence but the only thing that I can't remember is where I put the BNLS_CHOOSENLSREVISION (0x0D) in it.

I can't seem to place it.  Would this packet cause SID_AUTH_CHECK (0x51) to respond with an "0x101:  Invalid version"?

Kp has a good point about #pragma.  It's an option anyway, if you don't care about cross-platform compatibility.  :P
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Kp

Quote from: MyndFyre on December 31, 2004, 01:19 PMKp has a good point about #pragma.  It's an option anyway, if you don't care about cross-platform compatibility.  :P

Or even cross-compiler compatibility.  MSVC isn't the only Win32 compiler, you know.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!