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. The Lounge
  3. Meta-programming question

Meta-programming question

Scheduled Pinned Locked Moved The Lounge
questionc++javacsshelp
8 Posts 5 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.
  • N Offline
    N Offline
    Navin
    wrote on last edited by
    #1

    So, does anyone here have any cool tricks for being able to use constants across disparate languages/enviroments? For instance, what if I have some constant I'd like to use in both C++ and Java, but don't want to have to duplicate? Or even between code and build environment (e.g., C++ and makefile/project file, or between Java and an ANT file)? The problem, of course, with duplication is that if it changes in one spot you have to change it in the other. But I wonder if there are any better solutions? (Looking mostly for generic ideas, not so much specific implementations.) An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.

    S R V 3 Replies Last reply
    0
    • N Navin

      So, does anyone here have any cool tricks for being able to use constants across disparate languages/enviroments? For instance, what if I have some constant I'd like to use in both C++ and Java, but don't want to have to duplicate? Or even between code and build environment (e.g., C++ and makefile/project file, or between Java and an ANT file)? The problem, of course, with duplication is that if it changes in one spot you have to change it in the other. But I wonder if there are any better solutions? (Looking mostly for generic ideas, not so much specific implementations.) An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.

      S Offline
      S Offline
      Shog9 0
      wrote on last edited by
      #2

      You can use an external source for such constants. INI files, environmental variables, etc. Something all of your tools can or can be made to understand.

      Shog9

      I'm not the Jack of Diamonds... I'm not the six of spades. I don't know what you thought; I'm not your astronaut...

      N 1 Reply Last reply
      0
      • S Shog9 0

        You can use an external source for such constants. INI files, environmental variables, etc. Something all of your tools can or can be made to understand.

        Shog9

        I'm not the Jack of Diamonds... I'm not the six of spades. I don't know what you thought; I'm not your astronaut...

        N Offline
        N Offline
        Navin
        wrote on last edited by
        #3

        That's certainly a workable idea... and I've used it in some situations, but I'd like to find some scheme of doing it at compile-time. I suppose some custom build tools or something, that can generate code from an INI file might work... hmm... An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.

        S 1 Reply Last reply
        0
        • N Navin

          That's certainly a workable idea... and I've used it in some situations, but I'd like to find some scheme of doing it at compile-time. I suppose some custom build tools or something, that can generate code from an INI file might work... hmm... An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.

          S Offline
          S Offline
          Shog9 0
          wrote on last edited by
          #4

          AFAIK, most C/C++ compilers and make utilities allow environmental variables to define symbols used in code. Not sure about Java or anything else though.

          Shog9

          I'm not the Jack of Diamonds... I'm not the six of spades. I don't know what you thought; I'm not your astronaut...

          N 1 Reply Last reply
          0
          • S Shog9 0

            AFAIK, most C/C++ compilers and make utilities allow environmental variables to define symbols used in code. Not sure about Java or anything else though.

            Shog9

            I'm not the Jack of Diamonds... I'm not the six of spades. I don't know what you thought; I'm not your astronaut...

            N Offline
            N Offline
            Navin
            wrote on last edited by
            #5

            Yes, I have seen (at least in Visual C++) ways of turning an environment variable into a #define. And I've seen ways of getting Ant to be able to suck in a INI-like name=value file to make constants for it. But I can't think of any cross-language way to do any of that... aside from writing some tools of my own, I guess. An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.

            1 Reply Last reply
            0
            • N Navin

              So, does anyone here have any cool tricks for being able to use constants across disparate languages/enviroments? For instance, what if I have some constant I'd like to use in both C++ and Java, but don't want to have to duplicate? Or even between code and build environment (e.g., C++ and makefile/project file, or between Java and an ANT file)? The problem, of course, with duplication is that if it changes in one spot you have to change it in the other. But I wonder if there are any better solutions? (Looking mostly for generic ideas, not so much specific implementations.) An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.

              R Offline
              R Offline
              Roland Bar
              wrote on last edited by
              #6

              An Idea grown out of the actual survey: How about a Code Generator that builds the different files for the various languages? (haven't tried it for myself, so don't ask for a code generator that works for c++, java and [add your favorite programming language here] ) Greets Roland


              Wenn Du diesen Satz irgendwo liest, ignoriere ihn.

              Follow your Euro notes in their tracks

              P 1 Reply Last reply
              0
              • N Navin

                So, does anyone here have any cool tricks for being able to use constants across disparate languages/enviroments? For instance, what if I have some constant I'd like to use in both C++ and Java, but don't want to have to duplicate? Or even between code and build environment (e.g., C++ and makefile/project file, or between Java and an ANT file)? The problem, of course, with duplication is that if it changes in one spot you have to change it in the other. But I wonder if there are any better solutions? (Looking mostly for generic ideas, not so much specific implementations.) An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.

                V Offline
                V Offline
                V 0
                wrote on last edited by
                #7

                Actually if I'm not mistaken, the .NET framework already has to do something like that. It supports round about 20 languages, I suspect that compiled files like dll's or exe's should be able to 'talk' to each other if necessary regardless of the language they're written in. The first thing that comes up is serialization, XML, .... maybe you can look in to webservices? How do you do it there? good luck. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

                1 Reply Last reply
                0
                • R Roland Bar

                  An Idea grown out of the actual survey: How about a Code Generator that builds the different files for the various languages? (haven't tried it for myself, so don't ask for a code generator that works for c++, java and [add your favorite programming language here] ) Greets Roland


                  Wenn Du diesen Satz irgendwo liest, ignoriere ihn.

                  Follow your Euro notes in their tracks

                  P Offline
                  P Offline
                  peterchen
                  wrote on last edited by
                  #8

                  actually, I'm at something that would allow this - but I should keep my mouth shut for premature talking annoys the project gods... Welchen Satz?


                  I never really know a killer from a savior
                  boost your code || Fold With Us! || sighist | doxygen

                  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