Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] [Tier2] #include "agk.h" and compilation?

Author
Message
Piettro
12
Years of Service
User Offline
Joined: 27th Oct 2011
Location:
Posted: 6th Apr 2024 20:43
#include "agk.h" includes all header files for AppGameKit commands and it is necessary to put it into all .cpp files where AppGameKit commands are needed. My question is: Do these inclusions make the final .exe larger or do they increase the memory usage during game runtime? Or are these source files compiled multiple times?
This is more like a general C++ question, but I wonder if I should be careful with including the same header files, or if this is nothing to worry about at all. I use Visual Studio.
Thanks for all replies.

The author of this post has marked a post as an answer.

Go to answer

Dark Raven
9
Years of Service
User Offline
Joined: 27th Jul 2014
Location: United States
Posted: 7th Apr 2024 03:07
The headers will only be loaded once. There would be massive amount of errors if the headers were loaded and compiled each time they are called. Also most modern compilers should optimize the way they compile with the headers. The linking of the lib file will really be what sets the size of the exe file that is what the headers are giving you access to. But the headers have code at the top of the headers that detect whether it is already loaded so you really don't have to worry about agk's tier 2 headers.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 7th Apr 2024 04:01
This post has been marked by the post author as the answer.
For this we use "include guards"

if you look in the agk.h file you will see the code is wrapped in the following compiler directive



This is a compiler safe include guard, ie: will work in all compilers

when you create a header in VS it adds



This does exactly the same thing but is not compatible with all compilers, if you only use VS then this is good enough

using either ensures that the header file is only compiled into the project once, without these guards as Dark Raven said you would get a long list of redeclaration errors.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Piettro
12
Years of Service
User Offline
Joined: 27th Oct 2011
Location:
Posted: 7th Apr 2024 14:44
OK guys, now I understand it more.
Thank you for your help!

Login to post a reply

Server time is: 2024-05-04 07:57:52
Your offset time is: 2024-05-04 07:57:52