Hi everyone,
I'm writing a project in which I've defined several variables in a header file, included that header file in the main cpp file and tried to print the values of the defines from the main cpp file. When I do try to print them they get printed if I've run a function which also included the header file. I've shortened the code but it'll still work.
Please find the 3 files below:
Code:
------------------------- main.cpp -------------------------
#include "LinuxHardwareInfo.h"
#include <stdio.h>
int main (int argc, char* argv[])
{
printf("\n\n\n\n------------AA----HDD_SERIAL--AA---->> %s", HDD_SERIAL);
printf("\n\n\n\n----A-- ADDRESS OF HDD_SERIAL-A-->> %p\n", HDD_SERIAL );
createStorageFiles();
printf("\n\n\n\n--------BB--HDD_SERIAL----BB--->> %s", HDD_SERIAL);
printf("\n\n\n\n----B- ADDRESS OF HDD_SERIAL--B-->> %p\n", HDD_SERIAL );
return 0;
}
------------------------- end of main.cpp -------------------------
----------------------- LinuxHardwareInfo.cpp -----------------------
#include <stdio.h>
#include "LinuxHardwareInfo.h"
void createStorageFiles(void)
{
printf("\n\n\n\n-createStorageFiles- HDD_SERIAL-00->> %s", HDD_SERIAL);
printf("\n\n\n\ncreateStorageFiles ADDRESS OF H HDD_SERIAL-0->> %p\n", HDD_SERIAL);
printf("\n\n\n\ncreateStorageFiles- HDD_FIRMWARE-11->> %s", HDD_FIRMWARE);
printf("\n\n\n\ncreateStorageFiles- ADDRESS OF HDD_FIRMWARE -1->> %p\n", HDD_FIRMWARE);
printf("\n\n\n\ncreateStorageFiles- HDD_SERIAL_C-22->> %s", HDD_SERIAL_C);
printf("\n\n\n\n----createStorageFiles--- ADDRESS OF HDD_SERIAL_C------2-->> %p\n", HDD_SERIAL_C);
}
-------------------- end of LinuxHardwareInfo.cpp -------------------
----------------------- LinuxHardwareInfo.h -----------------------
#ifndef LINUXHARDWAREINFO_H
#define LINUXHARDWAREINFO_H
#define HDD_SERIAL_C "zzz yyy"
#define HDD_SERIAL "Serial Number"
#define HDD_FIRMWARE "nhhhj"
void createStorageFiles(void);
#endif
-------------------- end of LinuxHardwareInfo.h -------------------
-------------------- outputs -------------------
------------AA-------------HDD_SERIAL-----------AA----------------->>
------A--------- ADDRESS OF HDD_SERIAL-------A----------->> 0x80487c0
---------createStorageFiles--------- HDD_SERIAL-----------00---------------->> Serial Number
----createStorageFiles--- ADDRESS OF H HDD_SERIAL------0---------->> 0x80488ec
---------createStorageFiles--------- HDD_FIRMWARE -----------11---------------->> nhhhj
----createStorageFiles--- ADDRESS OF HDD_FIRMWARE -----1---------->> 0x80489a1
---------createStorageFiles--------- HDD_SERIAL_C-----------22---------------->> zzz yyy
----createStorageFiles--- ADDRESS OF HDD_SERIAL_C------2---------->> 0x8048a51
------------BB-------------HDD_SERIAL-----------BB----------------->>
------B--------- ADDRESS OF HDD_SERIAL-------B----------->> 0x80487c0\