New section with #define
-
Hi there, I'm looking for a way to create a new code/data section with a #define directive. The problem is, that the compiler does not allow #pragma directives within a #define directive. Example:
#define SECTION() #pragma data_seg( ".x" )
Is there another solution? Regards, Alex Don't try it, just do it! ;-)
-
Hi there, I'm looking for a way to create a new code/data section with a #define directive. The problem is, that the compiler does not allow #pragma directives within a #define directive. Example:
#define SECTION() #pragma data_seg( ".x" )
Is there another solution? Regards, Alex Don't try it, just do it! ;-)
What about:
#define SECTION_NAME ".X" #pragma data_seg( SECTION_NAME )
I am pretty sure anyplace you did not WANT the named section, you could just use#pragma data_seg()
I am pretty sure this resets it to the default data segment or has no effect if the data segment was not changed from the default in the first place. -
What about:
#define SECTION_NAME ".X" #pragma data_seg( SECTION_NAME )
I am pretty sure anyplace you did not WANT the named section, you could just use#pragma data_seg()
I am pretty sure this resets it to the default data segment or has no effect if the data segment was not changed from the default in the first place.The problem is that I want to set a new named section! It is quite easy: I create a new section with an array inside, which consists of many arrays from multiple cpp files. When compiling I merge the section with the data section and so it's possible to read the whole array from only one function (it's the same thing as the CRT does with e.g. constructors of static classes). I want to use a macro for that new section statement and the start of an array because it saves time when typing the code ;). Don't try it, just do it! ;-)
-
Hi there, I'm looking for a way to create a new code/data section with a #define directive. The problem is, that the compiler does not allow #pragma directives within a #define directive. Example:
#define SECTION() #pragma data_seg( ".x" )
Is there another solution? Regards, Alex Don't try it, just do it! ;-)
There is no super shortcut, but you can organize these. This is an example of how I do it:
#ifndef _TEXTSEG #define _TEXTSEG(name) ".text$" #name #endif #ifndef MY_CORE_SEG #define MY_CORE_SEG _TEXTSEG(MYS_CORE) #define MY_GDI_SEG _TEXTSEG(MYS_GDI) #endif
Then at the top of the source files I add the following as appropriate:#ifdef MY_GDI_SEG #pragma code_seg(MY_GDI_SEG) #endif
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke