• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Don't know if its art, but I need to know!

 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In C and C++ compilers there are often preprocessor commands. I am trying to duplicate some of the functionality I'm used to in other languages. Examples of things I would like to do -
- Be able to reference the build/compile time in my code
- Same as above but for the date
- Reference the line number the compiler is at
I know there are others, but I can't think of specifics right now. Some pseudo code in C/C++ demonstrating the above might be

Where __CTIME__ and #COMP_TIME are the compile time parameters.
Any thoughts?
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course, u can use java.util.GregorianCalendar class to do things with the Time and Date stuff...
Java does have java.lang.Runtime class to deal with the low level commands as well... But there is a limitation on how low Java can dig into the system...
 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I realize I can do date and time things, but the idea here is that the compiler is replacing, statically, those variable names. If today was Monday, 11 Jan 2004, then the __CTIME__ would be replaced during the compile only with that value. Its nothing that happens at runtime per se.
Its not something which is done very often, but when you need it, its handy to have.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess u might have to use Java Native Interface to apply the C/C++ native variables in the program...
I'm not that sure... But there are experts in the Other Java APIs forum who can help u in dealing with those native stuff...
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Java has no preparser such constructs are not available.
In C(++) the construct you mention would technically NOT give you the compilation time but the time the preparser was run at. This does not have to be the compilation time (it is possible to run only the preparser, and in large projects or on slow computers it is quite possible that there is a considerable (in machine terms) gap of several seconds if not longer between the preparser running and the compiler running.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are using Ant to do this. Basically, we do have a template file named Version.src with some java code declaring constants and placeholders for the actual values. The Ant script will copy the file to a Version.java file, thereby replacing the placeholders with actual values (using filters). Than the code gets compiled and other classes are able to refer to the constants with the current values.
Did that help?
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic