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. Making use of the preprocessor?

Making use of the preprocessor?

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 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.
  • M Offline
    M Offline
    moliate
    wrote on last edited by
    #1

    One of my classes keeps a lookup-table that is based on a few constants #define:d in the header. If one of the constants change before a recompile the table has to be recomputed, but otherwise it is defined as a constant:

    m_table[256] = {
    0x00000000, 0x6750096, 0xEEEE4455, 0x45DF5C75, 0xB6662D3D, 0x23EE4521,
    ...
    };

    I have a function that computes the table and prints it to standard output, so if I change one of the #define:d constants I can compile, run the function, cut-and-paste the table back to my sourcefile, and finally recompile.. Is there any way to make the preprocessor do this? The table-generating function is not simple enough to make into a macro.. Any suggestions? Thanks /moliate


    The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.

    Neil Gaiman - Cold Colours

    C J 2 Replies Last reply
    0
    • M moliate

      One of my classes keeps a lookup-table that is based on a few constants #define:d in the header. If one of the constants change before a recompile the table has to be recomputed, but otherwise it is defined as a constant:

      m_table[256] = {
      0x00000000, 0x6750096, 0xEEEE4455, 0x45DF5C75, 0xB6662D3D, 0x23EE4521,
      ...
      };

      I have a function that computes the table and prints it to standard output, so if I change one of the #define:d constants I can compile, run the function, cut-and-paste the table back to my sourcefile, and finally recompile.. Is there any way to make the preprocessor do this? The table-generating function is not simple enough to make into a macro.. Any suggestions? Thanks /moliate


      The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.

      Neil Gaiman - Cold Colours

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      nope, the preprocessor isn't that capable. but, take a look here: http://www.codeproject.com/string/CXR.asp i wrote a little system to do string encryption as part of the build process (roughly similar to your table generation). what i do is add a file to the project that causes VC to do a pre-build step. that pre-build step generates a source file (by calling off to a separate EXE), which is then compiled into the app. -c


      Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey

      Fractals

      M 1 Reply Last reply
      0
      • M moliate

        One of my classes keeps a lookup-table that is based on a few constants #define:d in the header. If one of the constants change before a recompile the table has to be recomputed, but otherwise it is defined as a constant:

        m_table[256] = {
        0x00000000, 0x6750096, 0xEEEE4455, 0x45DF5C75, 0xB6662D3D, 0x23EE4521,
        ...
        };

        I have a function that computes the table and prints it to standard output, so if I change one of the #define:d constants I can compile, run the function, cut-and-paste the table back to my sourcefile, and finally recompile.. Is there any way to make the preprocessor do this? The table-generating function is not simple enough to make into a macro.. Any suggestions? Thanks /moliate


        The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.

        Neil Gaiman - Cold Colours

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        If the function is not very complex, you can convert it to a constant-time template by using a technique called template metaprogramming. If you post the code maybe I can help you with it. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        M 1 Reply Last reply
        0
        • J Joaquin M Lopez Munoz

          If the function is not very complex, you can convert it to a constant-time template by using a technique called template metaprogramming. If you post the code maybe I can help you with it. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

          M Offline
          M Offline
          moliate
          wrote on last edited by
          #4

          Thanks! Googled for the term and found some nice pages. I'll try to do the conversion myself first - it will be a nice introduction to the concept. But I hope you don't mind if I ask you for help if I get stuck... /moliate


          The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.

          Neil Gaiman - Cold Colours

          J 1 Reply Last reply
          0
          • M moliate

            Thanks! Googled for the term and found some nice pages. I'll try to do the conversion myself first - it will be a nice introduction to the concept. But I hope you don't mind if I ask you for help if I get stuck... /moliate


            The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.

            Neil Gaiman - Cold Colours

            J Offline
            J Offline
            Joaquin M Lopez Munoz
            wrote on last edited by
            #5

            Good luck. TMP is an amazing technique, if difficult to tackle at first. Don't hesitate to ask for help. PS: If you're succesful, your case could be a nice introduction article to this technique here in CP. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

            1 Reply Last reply
            0
            • C Chris Losinger

              nope, the preprocessor isn't that capable. but, take a look here: http://www.codeproject.com/string/CXR.asp i wrote a little system to do string encryption as part of the build process (roughly similar to your table generation). what i do is add a file to the project that causes VC to do a pre-build step. that pre-build step generates a source file (by calling off to a separate EXE), which is then compiled into the app. -c


              Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey

              Fractals

              M Offline
              M Offline
              moliate
              wrote on last edited by
              #6

              Seems like a reasonable solution. Joaquín M López Muñoz also had an interesting suggestion. I'll first take a shot at template metaprogramming (I like to try out concepts new to me), but if that fails I'll go with a pre-build step. Thanks /moliate


              The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.

              Neil Gaiman - Cold Colours

              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