Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. New section with #define

New section with #define

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alexander M
    wrote on last edited by
    #1

    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! ;-)

    B J 2 Replies Last reply
    0
    • A Alexander M

      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! ;-)

      B Offline
      B Offline
      Blake Miller
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • B Blake Miller

        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.

        A Offline
        A Offline
        Alexander M
        wrote on last edited by
        #3

        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! ;-)

        1 Reply Last reply
        0
        • A Alexander M

          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! ;-)

          J Offline
          J Offline
          Joe Woodbury
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups