I created an include for loading\saving binary data. The language I am working with (Pawn) does not allow dynamic memory allocation so it must know array sizes at compile time. In my include file I have a dummy #define SIZE 1 which I have set to 1 and I want the user to redefine this include in their source file to the required size #define SIZE 32767. I tried using #undef but when I do a debug print in my app, it prints out the original value from the include. Any ideas?
Since you are posting this on a C++ forum, I assume you are writing a C++ extension for this language. If so, why would that extension have such limitations? (If you are not writing a C++ extension, but are instead asking for help with Pawn code, then it would seem to be off-topic for this forum.)
Blagh. Watered down = for the lose. And C is like a less capable version of C++ already.
If you are distributing your source code to the user, why not just give them a reminder to change the #define to whatever it is they have to use pre-compile? Why mess with undef? If it's their job to change the thing anyway, then I don't really see why you are taking the initiative on something like this.
Real advice: Use C++ and DMA the heck out of it.
However you want to put it, it is what it is. Pawn is the language that is used for what I am working with (AMX Mod X, www.amxmodx.org) on the HL1 game engine; I can't really choose to just use C++ (unless I turned this into a DLL which I don't want to do). I was trying to avoid the user having to edit the include w\ each compile. Again, I was just throwing the question out there.
Unfortunately, if you don't have DMA, arrays will have to be statically defined and must be allocated at compile time. Therefore there is no way to alter the data in execution. You can change the variables in-code, but you'd have to recompile first (which is, from what I gather, what you were asking about in your original post).
Not sure if I understand you correctly. I do not need to change\redimension any array sizes during runtime. I just want to alter a #define value found in an include file with the #define value in a source file, at compile time. It's weird because if I have SIZE defined in my include then I try to define it in my source file, it says "SIZE already defined" yet if #undef and then re-define it then print-out the value in my include, it will only show me the value defined in the include.
Here's a rough example of what I'm trying to do. I hope it helps
[include file]
#define SIZE 1 (dummy value just to make it compile)
if #undef and then re-define it then print-out the value in my include, it will only show me the value defined in the include.
This depends on where it's redefined vs. where you're printing.
Here's a rough example of what I'm trying to do. I hope it helps
This cannot be done in this way
The source file is already "too late" to redefine SIZE because SIZE was already used in the header. You'd have to #undef and re #define SIZE before it's ever used.
Basically... the whole idea of a "dummy" value won't work.
To bring up what someone else said... why can't you just change SIZE in the header?
I had a feeling this was the case. I don't want users to have to edit the include because it would be a hassle when the file is used in multiple plugins.Thanks for the replies
#ifndef SIZE
#error "Please #define SIZE as sizeof( YourStruct ) before including this header. See readme for details."
#endif
SomeFunction()
{
new Array[ SIZE ]; // or whatever
}