Need help with code
KeithJust
Posts: 18
Would anyone out there give me a hand and comment this code to help me undersand it? Still new here!
define_function VIDsetInput(integer input, _SwtInfo SwtOuts)
{
stack_var char cmd[70]
stack_var integer i
cmd = "'VI',itoa(input),'O'"
// Loop through all zones
for (i = 1; i <= 24; i++)
{
if (SwtOuts.vid_out)
{
cmd = "cmd,itoa(i),','"
}
}
define_function VIDsetInput(integer input, _SwtInfo SwtOuts)
{
stack_var char cmd[70]
stack_var integer i
cmd = "'VI',itoa(input),'O'"
// Loop through all zones
for (i = 1; i <= 24; i++)
{
if (SwtOuts.vid_out)
{
cmd = "cmd,itoa(i),','"
}
}
0
Comments
The code has a number of oddities:
(* Oops (a) It uses stack_var where it ought to use local_var Edited *)
(b) It takes no account of switching off outputs - maybe that's implicit in the command protocol
(c) The tSwitchInfo structure presumably contains nothing else, in which case it ought not be a structure
Why can?t it be a struct? Different strokes for different folks. A struct with one member is perfectly legal and also allows other members to be added easily. And who?s to say it contains nothing else as the definition isn?t posted? It?s possible the struct contains things like volume level, mute, bass level, etc.
I see nothing odd about the code at all. It may not be the way you or I would approach it but I wouldn?t take away anything from the person who wrote it.
Oops:
Its usage is local_var not stack_var - a stack_var is persistent across calls, it seems to me that you should only declare as stack_var when you intend to make use of that. I'm not suggesting the code as it stands is faulty - just that clarity is better served by using local_var, and a stack_var is a bug waiting to happen unless you explicitly want what it gives you.
Edit:
Its usage is stack_var not local_var - a local_var is persistent across calls, it seems to me that you should only declare as local_var when you intend to make use of that. I'm not suggesting the code as it stands is faulty - just that clarity is better served by using stack_var, and a local_var is a bug waiting to happen unless you explicitly want what it gives you.
Guys hope it's OK to post this here. Anyone somewhat familier with DXP that can help me with some code? What I have is a DXP generated program (that only allows adding composite video sources) and would like to modify the code to allow me to add component video sources. Can pay anyone willing to work on project today with Paypal. Again guys hope it's OK to post this here but I sure could use some help. Email me at keithjust@hotmail.com if interested. Thanks again.
Argh. Thanks Joe. In my current project there are 658 stack_vars and 0 local_vars.
I'll just go and have a lie-down.
I always use stack_vars, this is good - when I wrote the post that Joe corrected my brain must have been on holiday.