LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I handle global variables and include files when using multiple *.c and *.uir files in Lab Windows/CVI?

I am creating a progrm which has several small modules which interact. I would like to have seperate .uir files for some of the modules, as well as seperate .c files. How do I handle the include files and the global variables?
0 Kudos
Message 1 of 4
(4,725 Views)
I found useful and friendly a structure like this:

Include files:
I build a general .h file in which I store global variables, macros to use throghout the whole program and definitions for custom functions I develop.

Source files:
In every source file I #include the .h files for UIR and the general .h file made in the previous step (after the #include the CVI automatically adds while writing source code).
I also define a macro for every user interface file I use in the program, that way:

#define UIR1 "MyFile1.UIR"
#define UIR2 "MyFile2.UIR"

and obviously use those macros when opening a panel:
tmpH = LoadPanel (0, UIR1, MyPanel);

This is particularly useful in case of new releases: it's enough to modify the initial macros for the modified UIR files (I usu
ally change the name of the UIR file...) to have it changed in all the program whithout need to search and replace every occurrence of the UIR file name.

That way all works well: all definitions, macros and global variables are seen in all parts of my program and I can split it in how many source and UIR files I want.

Hope this helps
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(4,725 Views)
Roberto Bozzolo wrote in message
news:5065000000050000008B240000-986697009000@quiq.com...
> I found useful and friendly a structure like this:
>
> Include files:
> I build a general .h file in which I store global variables, macros to
> use throghout the whole program and definitions for custom functions I
> develop.
Isn't it a bit dodgy putting globals into header files,
every time you include the .h file you create a new
instance of the variable local to that file (unless
of course you extern it in the header file and have a
..c file somewhere with the actual definition, but thats
not much of a better solution)

Rather than using globals directly I always prefer to have the
variable that I want to use all through the program defined as
a static global within a .c file. I can then provide a number of
access functions which will change/return the values of the globals
This tends to make inadvertent modification and other problems less
common and makes the code easier to read(IMO). It also makes life a
lot easier in multithreaded apps as you can put the access functions
in a critical section something similar.

paulr



Dr Paul Rocca - Managing Director
Brill Engineering Ltd, 3 Longwood Court,
Love Lane, Cirencester, Gloucestershire
GL7 1YG. www.brill-eng.co.uk
Phone: 01285 883888 Fax: 01285 883876

Celebrating 10 Years of System Integration

Please note that calls may be recorded using our leading edge digital
recording product AudioPC.

Any opinions expressed in the email are those of the individual and not
necessarily of the Company. This email and any files transmitted with it
are confidential and solely for the use of the intended recipient. It
may contain material protected by lawyer-client privilege. If you are
not the intended recipient or the person responsible for delivering to
the intended recipient, be advised that you have received this email in
error and that any use is strictly prohibited. If you have received this
email in error please notify the Security Manager by telephone on +44
(0)1285 883821 or by email to security@brill-eng.co.uk
.
Message 3 of 4
(4,725 Views)
Hello,
imagine the answers already given were good.
The "low brow" method I use is to declare all globals at the top of the main file as usual and use the keyword extern to declare relevant globals in the other files.
EG
At top of main.c
int globalVariable = 0;

At top of another.c
extern int globalVariable;

Best Regards
Ken
0 Kudos
Message 4 of 4
(4,725 Views)