¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Question on finding the number of defined array elements.


Matt
 

I'm messing around with an upcoming project, and am looking to
determine the number of elements a string array has been assigned in
Simpl. Looking at S+ I see the directive isSignalDefined(). I have
the following code (not complete).

STRING_INPUT in$[10][25];

Function Main()
{
FOR(i = 10 to 1 Step -1)
{
IF(IsSignalDefined(in$[i]));
TRACE("i = %d", i);
BREAK;
}
}

Within Simpl, I have only two strings expanded on the symbol, but
NumSources always = 10, I was expecting to see 1.

Is this the correct approach and/or any advice on what's incorrect?


 

Hi Matt,

You need to put the statements after the IF in {}.

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@...> wrote:

I'm messing around with an upcoming project, and am looking to
determine the number of elements a string array has been assigned in
Simpl. Looking at S+ I see the directive isSignalDefined(). I have
the following code (not complete).

STRING_INPUT in$[10][25];

Function Main()
{
FOR(i = 10 to 1 Step -1)
{
IF(IsSignalDefined(in$[i]));
TRACE("i = %d", i);
BREAK;
}
}

Within Simpl, I have only two strings expanded on the symbol, but
NumSources always = 10, I was expecting to see 1.

Is this the correct approach and/or any advice on what's incorrect?


Chip Moody
 

And nuke the semicolon at the end of the IF statement line - I think
what you had is equivalent to "if this condition is met, do absolutely
squat". :)

Function Main()
{
FOR(i = 10 to 1 Step -1)
{
IF(IsSignalDefined(in$[i]))
{
TRACE("i = %d", i);
BREAK;
}
}
}

--- In Crestron@..., "Lindsay" <lindsayc@...> wrote:

Hi Matt,

You need to put the statements after the IF in {}.

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

I'm messing around with an upcoming project, and am looking to
determine the number of elements a string array has been assigned in
Simpl. Looking at S+ I see the directive isSignalDefined(). I have
the following code (not complete).

STRING_INPUT in$[10][25];

Function Main()
{
FOR(i = 10 to 1 Step -1)
{
IF(IsSignalDefined(in$[i]));
TRACE("i = %d", i);
BREAK;
}
}

Within Simpl, I have only two strings expanded on the symbol, but
NumSources always = 10, I was expecting to see 1.

Is this the correct approach and/or any advice on what's incorrect?


Matt
 

Thanks Lindsay and Chip, it's always puntuation isn't it. If I were
to remove the trace statement, could you use no brackets? If the
brackets are required, I guess there's another error in the help file.



Hi Matt,

You need to put the statements after the IF in {}.

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

I'm messing around with an upcoming project, and am looking to
determine the number of elements a string array has been assigned
in
Simpl. Looking at S+ I see the directive isSignalDefined(). I
have
the following code (not complete).

STRING_INPUT in$[10][25];

Function Main()
{
FOR(i = 10 to 1 Step -1)
{
IF(IsSignalDefined(in$[i]));
TRACE("i = %d", i);
BREAK;
}
}

Within Simpl, I have only two strings expanded on the symbol, but
NumSources always = 10, I was expecting to see 1.

Is this the correct approach and/or any advice on what's
incorrect?


 

True, but I always put them in so that if I do add another line I
don't mess up the execution order/nesting. (Didn't see the ; - fatal,
but a trace should have shown 10 outputs rather than just 1.)

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@...> wrote:

Thanks Lindsay and Chip, it's always puntuation isn't it. If I were
to remove the trace statement, could you use no brackets? If the
brackets are required, I guess there's another error in the help file.



Hi Matt,

You need to put the statements after the IF in {}.

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

I'm messing around with an upcoming project, and am looking to
determine the number of elements a string array has been assigned
in
Simpl. Looking at S+ I see the directive isSignalDefined(). I
have
the following code (not complete).

STRING_INPUT in$[10][25];

Function Main()
{
FOR(i = 10 to 1 Step -1)
{
IF(IsSignalDefined(in$[i]));
TRACE("i = %d", i);
BREAK;
}
}

Within Simpl, I have only two strings expanded on the symbol, but
NumSources always = 10, I was expecting to see 1.

Is this the correct approach and/or any advice on what's
incorrect?


Chip Moody
 

The Break; provided a nice exit and good reason why there was only 1
output... :)

And I'm on the other side of the fence with the single-statement IF.
If I'm 90% certain I'll never need to add more than one line I'll
quite happily do:

IF (x=1) DoSomething();

- Chip

--- In Crestron@..., "Lindsay" <lindsayc@...> wrote:

True, but I always put them in so that if I do add another line I
don't mess up the execution order/nesting. (Didn't see the ; - fatal,
but a trace should have shown 10 outputs rather than just 1.)

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

Thanks Lindsay and Chip, it's always puntuation isn't it. If I were
to remove the trace statement, could you use no brackets? If the
brackets are required, I guess there's another error in the help file.



Hi Matt,

You need to put the statements after the IF in {}.

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

I'm messing around with an upcoming project, and am looking to
determine the number of elements a string array has been assigned
in
Simpl. Looking at S+ I see the directive isSignalDefined(). I
have
the following code (not complete).

STRING_INPUT in$[10][25];

Function Main()
{
FOR(i = 10 to 1 Step -1)
{
IF(IsSignalDefined(in$[i]));
TRACE("i = %d", i);
BREAK;
}
}

Within Simpl, I have only two strings expanded on the symbol, but
NumSources always = 10, I was expecting to see 1.

Is this the correct approach and/or any advice on what's
incorrect?


Matt
 

I would have expected to see a compiler error on the fatal ; at the
end of an IF statement.



True, but I always put them in so that if I do add another line I
don't mess up the execution order/nesting. (Didn't see the ; -
fatal,
but a trace should have shown 10 outputs rather than just 1.)

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

Thanks Lindsay and Chip, it's always puntuation isn't it. If I
were
to remove the trace statement, could you use no brackets? If the
brackets are required, I guess there's another error in the help
file.



Hi Matt,

You need to put the statements after the IF in {}.

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

I'm messing around with an upcoming project, and am looking
to
determine the number of elements a string array has been
assigned
in
Simpl. Looking at S+ I see the directive isSignalDefined().
I
have
the following code (not complete).

STRING_INPUT in$[10][25];

Function Main()
{
FOR(i = 10 to 1 Step -1)
{
IF(IsSignalDefined(in$[i]));
TRACE("i = %d", i);
BREAK;
}
}

Within Simpl, I have only two strings expanded on the symbol,
but
NumSources always = 10, I was expecting to see 1.

Is this the correct approach and/or any advice on what's
incorrect?


 

Not fatal in that way, just fatal in term of doing what you want. And,
I blame it on being very hot here today (must be 40¡ãC in my office at
the moment) for my forgetting that the BREAK would exit on the first
loop. Chips on to it today.

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@...> wrote:

I would have expected to see a compiler error on the fatal ; at the
end of an IF statement.



True, but I always put them in so that if I do add another line I
don't mess up the execution order/nesting. (Didn't see the ; -
fatal,
but a trace should have shown 10 outputs rather than just 1.)

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

Thanks Lindsay and Chip, it's always puntuation isn't it. If I
were
to remove the trace statement, could you use no brackets? If the
brackets are required, I guess there's another error in the help
file.



Hi Matt,

You need to put the statements after the IF in {}.

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

I'm messing around with an upcoming project, and am looking
to
determine the number of elements a string array has been
assigned
in
Simpl. Looking at S+ I see the directive isSignalDefined().
I
have
the following code (not complete).

STRING_INPUT in$[10][25];

Function Main()
{
FOR(i = 10 to 1 Step -1)
{
IF(IsSignalDefined(in$[i]));
TRACE("i = %d", i);
BREAK;
}
}

Within Simpl, I have only two strings expanded on the symbol,
but
NumSources always = 10, I was expecting to see 1.

Is this the correct approach and/or any advice on what's
incorrect?


Joseph K. Vossen
 

the semi-colon after the if() is a valid statement from the parser's point of
view; it just doesn't do what you want/expect

here is a simple example of how that is useful; the following 'C' code copies
a NULL-terminated string, where 'p' points to the destination and 'q' points
to the source:. The while() terminates when the NULL terminating byte is hit.

while (*p++ = *q++)
; // <- note lone semi-colon

ya' just gotta love pointers...sure wish SIMPL+ had 'em.......

On Friday 23 January 2009 12:33 am, you wrote:
I would have expected to see a compiler error on the fatal ; at the
end of an IF statement.

True, but I always put them in so that if I do add another line I
don't mess up the execution order/nesting. (Didn't see the ; -
fatal, but a trace should have shown 10 outputs rather than just 1.)

Lindsay
[snip]


 

What error?

From the IF-ELSE:

"
IF ( <expression>)

[{]

<statements>

[}]

[ELSE]

[{]

<statements>

[}]]

...

In any section of the construct, if <statements> is only a single
statement, then the { and } characters may be omitted.
"

--- In Crestron@..., "Matt" <mjrtoo@...> wrote:

Thanks Lindsay and Chip, it's always puntuation isn't it. If I were
to remove the trace statement, could you use no brackets? If the
brackets are required, I guess there's another error in the help file.



Hi Matt,

You need to put the statements after the IF in {}.

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

I'm messing around with an upcoming project, and am looking to
determine the number of elements a string array has been assigned
in
Simpl. Looking at S+ I see the directive isSignalDefined(). I
have
the following code (not complete).

STRING_INPUT in$[10][25];

Function Main()
{
FOR(i = 10 to 1 Step -1)
{
IF(IsSignalDefined(in$[i]));
TRACE("i = %d", i);
BREAK;
}
}

Within Simpl, I have only two strings expanded on the symbol, but
NumSources always = 10, I was expecting to see 1.

Is this the correct approach and/or any advice on what's
incorrect?


 

Why?

You're just saying if some condition is true, then do nothing. Not
exactly something I'd typically see someone programming, but it *IS*
perfectly valid.

--- In Crestron@..., "Matt" <mjrtoo@...> wrote:

I would have expected to see a compiler error on the fatal ; at the
end of an IF statement.



True, but I always put them in so that if I do add another line I
don't mess up the execution order/nesting. (Didn't see the ; -
fatal,
but a trace should have shown 10 outputs rather than just 1.)

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

Thanks Lindsay and Chip, it's always puntuation isn't it. If I
were
to remove the trace statement, could you use no brackets? If the
brackets are required, I guess there's another error in the help
file.



Hi Matt,

You need to put the statements after the IF in {}.

Lindsay

--- In Crestron@..., "Matt" <mjrtoo@> wrote:

I'm messing around with an upcoming project, and am looking
to
determine the number of elements a string array has been
assigned
in
Simpl. Looking at S+ I see the directive isSignalDefined().
I
have
the following code (not complete).

STRING_INPUT in$[10][25];

Function Main()
{
FOR(i = 10 to 1 Step -1)
{
IF(IsSignalDefined(in$[i]));
TRACE("i = %d", i);
BREAK;
}
}

Within Simpl, I have only two strings expanded on the symbol,
but
NumSources always = 10, I was expecting to see 1.

Is this the correct approach and/or any advice on what's
incorrect?


 

I'm pretty sure the reason Crestron doesn't do Pointers is because of
support. They tend to perform a lot of support that doesn't seem to
be "their problem" - issues that are clearly programming mistakes, but
they do try to help resolve them (I know people knock TB for a lot,
but I mean they do try to be helpful if you get the right folks).

Can you just imagine the chaos of newbies trying to use pointers,
overwriting memory, blah blah blah, and Crestron trying to suck it up
and fix it/teach them?

As a professional programmer, sure, it would be great to have, but I
can definitely see why many things are limited.

Sometimes I don't understand the need to try to fix and assist with
blatant programming problems (If you were to call microsoft and whine
about how your system crashed because you did a NULL pointer access or
overwrite the bounds of your array, they'd probably just be like
"Uh....GO FIND AND FIX IT YOURSELF!!")





--- In Crestron@..., Joseph K. Vossen <jkv@...> wrote:

the semi-colon after the if() is a valid statement from the parser's
point of
view; it just doesn't do what you want/expect

here is a simple example of how that is useful; the following 'C'
code copies
a NULL-terminated string, where 'p' points to the destination and
'q' points
to the source:. The while() terminates when the NULL terminating
byte is hit.

while (*p++ = *q++)
; // <- note lone
semi-colon

ya' just gotta love pointers...sure wish SIMPL+ had 'em.......

On Friday 23 January 2009 12:33 am, you wrote:
I would have expected to see a compiler error on the fatal ; at the
end of an IF statement.

True, but I always put them in so that if I do add another line I
don't mess up the execution order/nesting. (Didn't see the ; -
fatal, but a trace should have shown 10 outputs rather than just 1.)

Lindsay
[snip]


Joseph K. Vossen
 

agreed...in my non-Crestron circle of travels in the past, I have found that a *good* understanding of pointers separates the good programmers from the great ones. And then when you jump into function pointers, that opens up a whole new world of fun.....

having pointers in SIMPL+ would benefit, for example, those tasks that perform a *lot* of parsing, such as busting up XML pages. Sure one can do it now with what is available, I just think the code would be a bit more compact, IMHO

-----Original Message-----
From: fooguy89 <fooguy89@...>
Sent: Jan 23, 2009 10:53 AM
To: Crestron@...
Subject: [Crestron] Re: Question on finding the number of defined array elements.

I'm pretty sure the reason Crestron doesn't do Pointers is because of
support. They tend to perform a lot of support that doesn't seem to
be "their problem" - issues that are clearly programming mistakes, but
they do try to help resolve them (I know people knock TB for a lot,
but I mean they do try to be helpful if you get the right folks).

Can you just imagine the chaos of newbies trying to use pointers,
overwriting memory, blah blah blah, and Crestron trying to suck it up
and fix it/teach them?

As a professional programmer, sure, it would be great to have, but I
can definitely see why many things are limited.

Sometimes I don't understand the need to try to fix and assist with
blatant programming problems (If you were to call microsoft and whine
about how your system crashed because you did a NULL pointer access or
overwrite the bounds of your array, they'd probably just be like
"Uh....GO FIND AND FIX IT YOURSELF!!")


--- In Crestron@..., Joseph K. Vossen <jkv@...> wrote:

the semi-colon after the if() is a valid statement from the parser's
point of view; it just doesn't do what you want/expect

here is a simple example of how that is useful; the following 'C'
code copies a NULL-terminated string, where 'p' points to the destination and
'q' points to the source:. The while() terminates when the NULL terminating
byte is hit.

while (*p++ = *q++)
; // <- note lone semi-colon

ya' just gotta love pointers...sure wish SIMPL+ had 'em.......

On Friday 23 January 2009 12:33 am, you wrote:
I would have expected to see a compiler error on the fatal ; at the
end of an IF statement.

True, but I always put them in so that if I do add another line I
don't mess up the execution order/nesting. (Didn't see the ; -
fatal, but a trace should have shown 10 outputs rather than just 1.)

Lindsay


Chris Erskine
 

I agree that not only would your code be more compact but more efficient since you would not have to be copying data around all over. On the other hand, pointers would cause so much more problems in the code that systems would be crashing all over. Crestron would require better TB personnel and better tools since you would need a debugger that would let you step through the S+ code when it was running.



Chris

-----Original Message-----
From: Crestron@... [mailto:Crestron@...] On Behalf Of Joseph K. Vossen
Sent: Friday, January 23, 2009 9:06 AM
To: Crestron@...
Subject: Re: [Crestron] Re: Question on finding the number of defined array elements.

agreed...in my non-Crestron circle of travels in the past, I have found that a *good* understanding of pointers separates the good programmers from the great ones. And then when you jump into function pointers, that opens up a whole new world of fun.....


having pointers in SIMPL+ would benefit, for example, those tasks that perform a *lot* of parsing, such as busting up XML pages. Sure one can do it now with what is available, I just think the code would be a bit more compact, IMHO

-----Original Message-----
From: fooguy89 <fooguy89@...>
Sent: Jan 23, 2009 10:53 AM
To: Crestron@...
Subject: [Crestron] Re: Question on finding the number of defined array elements.

I'm pretty sure the reason Crestron doesn't do Pointers is because of
support. They tend to perform a lot of support that doesn't seem to
be "their problem" - issues that are clearly programming mistakes, but
they do try to help resolve them (I know people knock TB for a lot,
but I mean they do try to be helpful if you get the right folks).

Can you just imagine the chaos of newbies trying to use pointers,
overwriting memory, blah blah blah, and Crestron trying to suck it up
and fix it/teach them?

As a professional programmer, sure, it would be great to have, but I
can definitely see why many things are limited.

Sometimes I don't understand the need to try to fix and assist with
blatant programming problems (If you were to call microsoft and whine
about how your system crashed because you did a NULL pointer access or
overwrite the bounds of your array, they'd probably just be like
"Uh....GO FIND AND FIX IT YOURSELF!!")


--- In Crestron@..., Joseph K. Vossen <jkv@...> wrote:

the semi-colon after the if() is a valid statement from the parser's
point of view; it just doesn't do what you want/expect

here is a simple example of how that is useful; the following 'C'
code copies a NULL-terminated string, where 'p' points to the destination and
'q' points to the source:. The while() terminates when the NULL terminating
byte is hit.

while (*p++ = *q++)
; // <- note lone semi-colon

ya' just gotta love pointers...sure wish SIMPL+ had 'em.......

On Friday 23 January 2009 12:33 am, you wrote:
I would have expected to see a compiler error on the fatal ; at the
end of an IF statement.

True, but I always put them in so that if I do add another line I
don't mess up the execution order/nesting. (Didn't see the ; -
fatal, but a trace should have shown 10 outputs rather than just 1.)

Lindsay


------------------------------------



Check out the Files area for useful modules, documents, and drivers.

A contact list of Crestron dealers and programmers can be found in the Database area.
Yahoo! Groups Links


Jeremy Weatherford
 

What would you do with pointers that you can't do with array indexes?
Function arguments are already passed by reference, so what's this
"copying data around all over"?

It's easy to bounds-check array indexes to keep a program from doing
bad things when it screws up. It's hard to check pointer arithmetic.
It's also hard to get dynamic memory allocation right. I think
Crestron has struck a good balance with SIMPL+'s features, power, and
robustness.

Jeremy

On Fri, Jan 23, 2009 at 10:12 AM, Chris Erskine <chris@...> wrote:
I agree that not only would your code be more compact but more efficient since you would not have to be copying data around all over. On the other hand, pointers would cause so much more problems in the code that systems would be crashing all over. Crestron would require better TB personnel and better tools since you would need a debugger that would let you step through the S+ code when it was running.


 

I agree, that in the right hands, pointers are extremely powerful,
but I feel Crestron have chosen wisely here.

As foo's already said, the potential for misuse of pointers would
open us up to a world of pain. I'm not knocking anyone here; we all
have to start somewhere, but there do appear to be a lot of guys
programming systems with some pretty shaky foundations in procedural
languages, and even simple syntactic issues (like the root of this
thread) could wreak havoc scrambling your processor's brains. So I
suppose you could argue "Pointers don't kill processors, programmers
do" ;-) Anyway - anyone who's had to debug bad pointer arithmetic
knows what a time-consuming process it can be, and that's on your own
code - it's 100x harder when it's someone else's.

The efficiency argument can be mitigated too - you can always use
ByRef in your function declarations (in fact, you can't avoid it with
STRING). I've written an XML parser that doesn't move the XML
document at all (though it does mean creating a lot of markers...
which I guess are just my version of (safe?) pointers).

This is where foo pipes up to say that Crestron's implementation of
ByRef does actually make a copy the data 8)

Now... if they'd just implement multiple-inheritance in S+ (*JOKING!*)

Ol

--- In Crestron@..., "Joseph K. Vossen" <jkv@...> wrote:

agreed...in my non-Crestron circle of travels in the past, I have
found that a *good* understanding of pointers separates the good
programmers from the great ones. And then when you jump into
function pointers, that opens up a whole new world of fun.....

having pointers in SIMPL+ would benefit, for example, those tasks
that perform a *lot* of parsing, such as busting up XML pages. Sure
one can do it now with what is available, I just think the code would
be a bit more compact, IMHO

-----Original Message-----
From: fooguy89 <fooguy89@...>
Sent: Jan 23, 2009 10:53 AM
To: Crestron@...
Subject: [Crestron] Re: Question on finding the number of defined
array elements.

I'm pretty sure the reason Crestron doesn't do Pointers is because
of
support. They tend to perform a lot of support that doesn't seem
to
be "their problem" - issues that are clearly programming mistakes,
but
they do try to help resolve them (I know people knock TB for a lot,
but I mean they do try to be helpful if you get the right folks).

Can you just imagine the chaos of newbies trying to use pointers,
overwriting memory, blah blah blah, and Crestron trying to suck it
up
and fix it/teach them?

As a professional programmer, sure, it would be great to have, but
I
can definitely see why many things are limited.

Sometimes I don't understand the need to try to fix and assist with
blatant programming problems (If you were to call microsoft and
whine
about how your system crashed because you did a NULL pointer
access or
overwrite the bounds of your array, they'd probably just be like
"Uh....GO FIND AND FIX IT YOURSELF!!")


--- In Crestron@..., Joseph K. Vossen <jkv@> wrote:

the semi-colon after the if() is a valid statement from the
parser's
point of view; it just doesn't do what you want/expect

here is a simple example of how that is useful; the following 'C'
code copies a NULL-terminated string, where 'p' points to the
destination and
'q' points to the source:. The while() terminates when the NULL
terminating
byte is hit.

while (*p++ = *q++)
; // <- note
lone semi-colon

ya' just gotta love pointers...sure wish SIMPL+ had 'em.......

On Friday 23 January 2009 12:33 am, you wrote:
I would have expected to see a compiler error on the fatal ;
at the
end of an IF statement.

True, but I always put them in so that if I do add another
line I
don't mess up the execution order/nesting. (Didn't see
the ; -
fatal, but a trace should have shown 10 outputs rather than
just 1.)

Lindsay


Chip Moody
 

Part of me wants to ROTFL over that, but no - that's just not funny. :)

- Chip

--- In Crestron@..., "Oliver Hall" <oliver.hall@...> wrote:

Now... if they'd just implement multiple-inheritance in S+ (*JOKING!*)

Ol


Joseph K. Vossen
 

[snip]

Now... if they'd just implement multiple-inheritance in S+ (*JOKING!*)
don't even go there :))


Chip Moody
 

This is actually something I was wondering about when I made the XM
Now Playing module, and just couldn't bring myself to write TBTS on this.

In the XM module, I take the result of a MID function and pass it to
one of my own functions that in turn manipulates the results of the
MID and returns the result of THAT manipulation.

If I could abbreviate/abstract it, it might look something like this:

STRING_FUNCTION Fudge (STRING src$)
{
// Among other things, do something along these lines:
Garbage$ = REMOVE(";",src$);
// Blah blah, more code here...
RETURN (MyProcessedString$);
}

PUSH Go
{
tx$ = Fudge (MID(SomeExistingStringVar$,3,6));
}

My mindset was that the result of MID doesn't exist as a variable,
so I can't really mess around with the contents of that result like I
show in that snippet up there. So in the ACTUAL module, one of the
first things that happens inside Fudge is I copy "src$" into local
variable "temp$", then work on temp$ exclusively:

STRING_FUNCTION Fudge (STRING src$)
{
temp$ = src$;
// Among other things, do something along these lines:
Garbage$ = REMOVE(";",temp$);
// Blah blah, more code here...
RETURN (MyProcessedString$);
}

Does that make sense? Does anyone know for certain if what I did
was required, or does the result of MID (or any other string function
for that matter) exist in some malleable state that I can operate on?

Thanks,
- Chip

--- In Crestron@..., "Oliver Hall" <oliver.hall@...> wrote:

This is where foo pipes up to say that Crestron's implementation of
ByRef does actually make a copy the data 8)


 

Disclaimer: TOTAL GUESS!

I'd say that in the case of a function that *returns* a value, that
value must be created on the stack. So your MID is creating a new
string. That "new" string is then either assigned to a string
variable or returned to the calling function.

So: you're not passing ByRef in this case, but essentially "returning
ByVal". Meaning, you don't need to use temp$.

The MID(SomeExisting...) is creating a new string, passing it ByRef
to Fudge, which then modifies that *new* string (by the REMOVE()).

I think...

I'll have to test that theory - but not now... it's Beer O'Clock!

Enjoy your weekends everyone!
Ol

--- In Crestron@..., "Chip Moody" <cfm@...> wrote:


This is actually something I was wondering about when I made the
XM
Now Playing module, and just couldn't bring myself to write TBTS on
this.

In the XM module, I take the result of a MID function and pass it
to
one of my own functions that in turn manipulates the results of the
MID and returns the result of THAT manipulation.

If I could abbreviate/abstract it, it might look something like
this:

STRING_FUNCTION Fudge (STRING src$)
{
// Among other things, do something along these lines:
Garbage$ = REMOVE(";",src$);
// Blah blah, more code here...
RETURN (MyProcessedString$);
}

PUSH Go
{
tx$ = Fudge (MID(SomeExistingStringVar$,3,6));
}

My mindset was that the result of MID doesn't exist as a variable,
so I can't really mess around with the contents of that result like
I
show in that snippet up there. So in the ACTUAL module, one of the
first things that happens inside Fudge is I copy "src$" into local
variable "temp$", then work on temp$ exclusively:

STRING_FUNCTION Fudge (STRING src$)
{
temp$ = src$;
// Among other things, do something along these lines:
Garbage$ = REMOVE(";",temp$);
// Blah blah, more code here...
RETURN (MyProcessedString$);
}

Does that make sense? Does anyone know for certain if what I did
was required, or does the result of MID (or any other string
function
for that matter) exist in some malleable state that I can operate
on?

Thanks,
- Chip


--- In Crestron@..., "Oliver Hall" <oliver.hall@> wrote:

This is where foo pipes up to say that Crestron's implementation
of
ByRef does actually make a copy the data 8)