Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 13th, 2005, 7:59 AM   #1
lgiordano
Newbie
 
Join Date: Feb 2005
Posts: 8
Rep Power: 0 lgiordano is on a distinguished road
Read Programm Version from outside

Hi, this is my problem:
I have two programms (both made by me): my main application and an external one. The external one must read the main app version. The version is declared as: #define APP_VERSION (XX). I dont know very much about compilers/linkers, but I think that the defines are not mapped into the exe. However, I use APP_VERSION to print in some places of my app, so somewhere in exe it should appear. But, as the main app changes some code in new versions, I can't read in a some fixed exe position, and be sure to always read version ok.
My question is, how can I make some code, or tell the compiler/linker to map a constant in the exe in an fixed position? Until now, I am doing this:
main() 
{
  /* I only use this printf() to print version, not because I want to show it */
  /* here, but to make it appear in the exe in a fixed pos, as it is the first */  
  /* instruction executed, so it is easy to find it in exe */
  printf("%d", APP_VERSION); 
...
...

}
Best wishes from Argentina!
lgiordano is offline   Reply With Quote
Old Jul 13th, 2005, 8:44 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Why don't you just declare a local variable there and initialize it to the version number? Essentially, that's what you're doing with the parameter to "printf".
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 13th, 2005, 8:49 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
If the main app is always running, you can use an environment variable...

The following example changes the value of the HOME environment variable to the value /usr/home.

#include <stdlib.h>
...
static char *var = "HOME=/usr/home";
int ret;

ret = putenv(var);
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jul 13th, 2005, 9:51 AM   #4
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
I think he means something like fingerprinting or image file version identifiers.

Let's try the easiest one put a what string at the beginning of a string. Put this near the top of your code
static char *MYidentifier="@(#) programname version 1.1.0";

ident and what will display it for you. You can write your own ident module -
call strstr() to find the start of the identifier.
jim mcnamara is offline   Reply With Quote
Old Jul 13th, 2005, 9:58 AM   #5
lgiordano
Newbie
 
Join Date: Feb 2005
Posts: 8
Rep Power: 0 lgiordano is on a distinguished road
Thanks for the replies.
DaWei, before doing the printf() I had tought about your suggestion. However, I wasn't sure about compiler's optimization, so if I declare a variable but I dont use, the compiler may eliminate it, even when I initialized it. Certainly I could do this:
main()
{
  unsigned int nVer = APP_VERSION;
  nVer = nVer; // Compiler, optimize all but no this!
}

I can also add some ASM code, I will test it.
By the way, please correct me if I am wrong, I think there is a way to tell the linker to add a fixed block in a fixed position in the exe.

Regards,
lgiordano is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:07 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC