04.04.2015, 12:13
How to use #pragma
Today, I will teach you how to use #pragma. A useful directive which will fix a wide array of compiler warnings.
Usage
i lied
#pragma is a directive used to change compiler settings. It is not a warning fixer.
I always see people advising others to use #pragma to remove warnings from their script. The warnings are only silenced - they do not magically disappear.
Instead, you will learn how to avoid using it. Warnings should never be silenced - they should be fixed the correct way!
#pragma tabsize
This sets the tab size, which is set to 4 by default. When you set it to zero, you are basically allowing for unreadable code in your script.
You should never have to set the tab size. Why do you want to set it anyway? Learn to indent your code correctly, and you won't have a problem.
#pragma dynamic
This code:
Dynamically sets the size of the stack. Without it, you may receive something along the lines of:
This warning is caused by sparse arrays, unnecessary string sizes, and using up a lot of data.
Ask yourself this: do you really need to use all of that space? Why are there 2,000 slots allocated for HouseInfo, when you only use 100 slots? There are many ways to reduce data usage.
That array is 400 kilobytes big, not including enumerator data. That is nothing compared to today's standards, but it still matters, and there is a way to reduce it.
Let's say we have an average of 40 items of furniture per house. We can easily reduce it to:
Of course, not every house will contain 40 items of furniture. The size of this array is now 40 kilobytes, as opposed to the 400 kilobytes from the other one.
Conclusion
TL;DR - Don't use #pragma to fix compiler warnings.
Other versions of Pawno use different compiler settings. SA-MP uses its own settings, so it's important that you adapt to it.
In case you didn't notice the underlined links in this post, you can read my tutorials about packed strings and also sparse arrays
Today, I will teach you how to use #pragma. A useful directive which will fix a wide array of compiler warnings.
Usage
i lied
#pragma is a directive used to change compiler settings. It is not a warning fixer.
I always see people advising others to use #pragma to remove warnings from their script. The warnings are only silenced - they do not magically disappear.
Instead, you will learn how to avoid using it. Warnings should never be silenced - they should be fixed the correct way!
#pragma tabsize
This sets the tab size, which is set to 4 by default. When you set it to zero, you are basically allowing for unreadable code in your script.
You should never have to set the tab size. Why do you want to set it anyway? Learn to indent your code correctly, and you won't have a problem.
#pragma dynamic
This code:
pawn Код:
#pragma dynamic 1000000
Код:
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase Header size: 19036 bytes Code size: 1327124 bytes Data size: 43915204 bytes Stack/heap size: 16384 bytes; estimated max. usage: unknown, due to recursion Total requirements:45277748 bytes
Ask yourself this: do you really need to use all of that space? Why are there 2,000 slots allocated for HouseInfo, when you only use 100 slots? There are many ways to reduce data usage.
pawn Код:
#define MAX_HOUSES 1000
#define MAX_FURNITURE 100 // Per house.
new FurnitureInfo[MAX_HOUSES][MAX_FURNITURE][e_FURNITURE_DATA];
Let's say we have an average of 40 items of furniture per house. We can easily reduce it to:
pawn Код:
new FurnitureInfo[MAX_HOUSES * 40][e_FURNITURE_DATA];
Conclusion
TL;DR - Don't use #pragma to fix compiler warnings.
Other versions of Pawno use different compiler settings. SA-MP uses its own settings, so it's important that you adapt to it.
In case you didn't notice the underlined links in this post, you can read my tutorials about packed strings and also sparse arrays