Keyboard Shortcuts
ctrl + shift + ? :
Show all keyboard shortcuts
ctrl + g :
Navigate to a group
ctrl + shift + f :
Find
ctrl + / :
Quick actions
esc to dismiss
Likes
Search
Question on finding the number of defined array elements.
Hi All,
I am really sorry that my post sounded condescending. That wasn't the intention, and I absolutely agree with the points that this is a forum to ask questions, whatever the level. I truly hope I haven't put anyone off asking for help in the future. At the risk of digging an even bigger hole... what I was getting at was: Crestron have done the right thing *not* to include pointers in S+. S+ is (I think the majority would agree) only an extension to Crestron's fundamental, symbolic, development language. As Matt pointed (no pun intended!) out, there are truly great SIMPL Windows programmers out there (and I don't count myself in there by any stretch) who don't do, or care to do, much with S+. Given that S+ isn't therefore an essential core competency for Crestron programming, the inclusion of pointers in the language would present a dangerous temptation. This allows people to dabble in S+ without too much risk of nuking an otherwise perfectly good system. Note: For those that don't agree that S+ is a non-core competency, please don't write back. Life's too short. And my personal opinion is that S+ is a very useful extension... just not core :-p Ol --- In Crestron@..., "Matt" <mjrtoo@...> wrote: procedural languages, and even simple syntactic issues (like the root of thisprogrammers do" ;-)not a procedural language, some people might even say that it's notMEANT to be programmed with S+.is good too...right? ;) |
Matt
Right on, I might add that trying to not put someone down while
helping is a plus! starting with assembler and moving up into what are called 4GL and true Object Oriented languages. They each have their strong points and their weaknesses. Each have places where they are the better language for the usage. C was designed to be a higher level language than assembler but still allow some of the power of assembler with its pointers. with OS's) where their language or way of programming is the best or only way. For the good programmers, a language is just a tool where they find the strengths and weaknesses and how to use it for the job being done. their strengths and weaknesses just like any other tool. There are some places where Simpl is the right tool and some where S+ is the right one. Since Simpl is the "native" language of the Crestron processors and is required for everything you do programming in the Crestron environment, it is the one that most time should be spent on. When you find places S+ is the better language, use it but also understand where it should and should not be used. crop' programmers. I am still trying to learn this envirnoment. The way this type of group works isif you can help, do so. Some of the times when you try to help, you find you are wrong but most of the times, you are not. Some of the times, you find that you may be right but there is a better way. Behalf Of Matt Sent: Friday, January 23, 2009 5:10 PMarray elements. not a procedural language, some people might even say that it's notMEANT to be programmed with S+.is good too...right? ;) the Database area. Yahoo! Groups Links |
Chip Moody
Yeah. +1. I'd +2, but that would just be tacky of me.
toggle quoted message
Show quoted text
Great post, Chris. - Chip --- In Crestron@..., "fellatedone" <j.legge@...> wrote:
|
Jeremy Weatherford
An integer index is just as effective as a pointer into a string. The
toggle quoted message
Show quoted text
other issue you bring up is that strings are not null-terminated. Since we constantly work with serial protocols that use null bytes, I happen to think this is a very good thing. If you want to pass substrings around without recopying, just pass an index and a length, and have the receiving routine only look at those characters. Don't forget about byte() and setbyte() when you're lamenting the lack of pointers -- they make up for the fact that you can't index a string like an array of characters. Jeremy On Fri, Jan 23, 2009 at 5:16 PM, Chris Erskine <chris@...> wrote:
One of the things that I would do with pointers was for strings with delimiters, you would null out the delimiter and by using pointers, you could point to the start of the string without having to copy the data into new fields. There are a number of other uses that they can be used for but that was the one I was thinking about when Joseph talked about breaking up the XML files. |
fellatedone
Fantastic post. Thank you.
-JOHN --- In Crestron@..., Chris Erskine <chris@...> wrote: starting with assembler and moving up into what are called 4GL and true Object Oriented languages. They each have their strong points and their weaknesses. Each have places where they are the better language for the usage. C was designed to be a higher level language than assembler but still allow some of the power of assembler with its pointers. with OS's) where their language or way of programming is the best or only way. For the good programmers, a language is just a tool where they find the strengths and weaknesses and how to use it for the job being done. strengths and weaknesses just like any other tool. There are some places where Simpl is the right tool and some where S+ is the right one. Since Simpl is the "native" language of the Crestron processors and is required for everything you do programming in the Crestron environment, it is the one that most time should be spent on. When you find places S+ is the better language, use it but also understand where it should and should not be used. crop' programmers. I am still trying to learn this envirnoment. The way this type of group works isif you can help, do so. Some of the times when you try to help, you find you are wrong but most of the times, you are not. Some of the times, you find that you may be right but there is a better way. Behalf Of Matt Sent: Friday, January 23, 2009 5:10 PMarray elements.
the Database area. Yahoo! Groups Links |
Chris Erskine
Over the years, I have programmed in many different languages starting with assembler and moving up into what are called 4GL and true Object Oriented languages. They each have their strong points and their weaknesses. Each have places where they are the better language for the usage. C was designed to be a higher level language than assembler but still allow some of the power of assembler with its pointers.
toggle quoted message
Show quoted text
For some, programming languages are more of a religious war (like with OS's) where their language or way of programming is the best or only way. For the good programmers, a language is just a tool where they find the strengths and weaknesses and how to use it for the job being done. Simpl and S+ are just programming languages. We need to learn their strengths and weaknesses just like any other tool. There are some places where Simpl is the right tool and some where S+ is the right one. Since Simpl is the "native" language of the Crestron processors and is required for everything you do programming in the Crestron environment, it is the one that most time should be spent on. When you find places S+ is the better language, use it but also understand where it should and should not be used. I know that in this environment, I am not one of your 'cream of the crop' programmers. I am still trying to learn this envirnoment. The way this type of group works isif you can help, do so. Some of the times when you try to help, you find you are wrong but most of the times, you are not. Some of the times, you find that you may be right but there is a better way. Chris -----Original Message-----
From: Crestron@... [mailto:Crestron@...] On Behalf Of Matt Sent: Friday, January 23, 2009 5:10 PM To: Crestron@... Subject: [Crestron] Re: Question on finding the number of defined array elements. ...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" ;-) Hey, I resemble that comment. ;) But in all honesty, I think the majority of Crestron programmers don't have procedural backgrounds, and don't really need to, it's not a procedural language, some people might even say that it's not MEANT to be programmed with S+. A lot of the programmers here are the 'cream of the crop' and I for one appreciate the help, but I also like to think I help as well. Sure, not with pointers or 'dynamic memory assignment' or what-have- you, and also make syntax errors that I ask about, but helping out with a 'I can't figure out how the example checksum is calculated' is good too...right? ;) ------------------------------------ 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 |
Matt
...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" ;-) Hey, I resemble that comment. ;) But in all honesty, I think the majority of Crestron programmers don't have procedural backgrounds, and don't really need to, it's not a procedural language, some people might even say that it's not MEANT to be programmed with S+. A lot of the programmers here are the 'cream of the crop' and I for one appreciate the help, but I also like to think I help as well. Sure, not with pointers or 'dynamic memory assignment' or what-have- you, and also make syntax errors that I ask about, but helping out with a 'I can't figure out how the example checksum is calculated' is good too...right? ;) |
Joseph K. Vossen
that's how many implementations of strtok(3) work.
toggle quoted message
Show quoted text
On Friday 23 January 2009 06:18 pm, you wrote:
Oh Duh... Sorry, I forgot the whole part about being able to point to |
Oh Duh... Sorry, I forgot the whole part about being able to point to individual character positions in a "string".
toggle quoted message
Show quoted text
Makes much more sense -- Lincoln King-Cliby, CTS Applications Engineer ControlWorks Consulting, LLC V: 440.729.4640 x1107 F: 440.729.0884 I: Crestron Authorized Independent Programmer -----Original Message-----
From: Crestron@... [mailto:Crestron@...] On Behalf Of Chris Erskine Sent: Friday, January 23, 2009 6:17 PM To: Crestron@... Subject: RE: RE: [Crestron] Re: Question on finding the number of defined array elements. One of the things that I would do with pointers was for strings with delimiters, you would null out the delimiter and by using pointers, you could point to the start of the string without having to copy the data into new fields. There are a number of other uses that they can be used for but that was the one I was thinking about when Joseph talked about breaking up the XML files. Chris -----Original Message----- From: Crestron@... [mailto:Crestron@...] On Behalf Of Lincoln King-Cliby Sent: Friday, January 23, 2009 4:08 PM To: 'Crestron@...' Subject: RE: [Crestron] Re: Question on finding the number of defined array elements. Isn't' that why you pass strings by reference unless you have a good reason for passing them by value (or you're dealing with one of the S+ quirks that won't allow a passing byref, like IIRC, a serial input)? Or would pointers open up another advantageous option that I'm forgetting at the moment (it's been far too long since the last time I played with a language the formally supported pointers :(... but they are uber cool. Took me most of my first semester of AP CompSci in high school to figure the point out, but after that... wow!) Lincoln -- Lincoln King-Cliby, CTS Applications Engineer ControlWorks Consulting, LLC V: 440.729.4640 x1107 F: 440.729.0884 I: Crestron Authorized Independent Programmer -----Original Message----- From: Crestron@... [mailto:Crestron@...] On Behalf Of Chris Erskine Sent: Friday, January 23, 2009 11:12 AM To: Crestron@... Subject: RE: [Crestron] Re: Question on finding the number of defined array elements. 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@...> ------------------------------------ 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 ------------------------------------ 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 ------------------------------------ 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 ------------------------------------ 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 |
Chris Erskine
One of the things that I would do with pointers was for strings with delimiters, you would null out the delimiter and by using pointers, you could point to the start of the string without having to copy the data into new fields. There are a number of other uses that they can be used for but that was the one I was thinking about when Joseph talked about breaking up the XML files.
toggle quoted message
Show quoted text
Chris -----Original Message-----
From: Crestron@... [mailto:Crestron@...] On Behalf Of Lincoln King-Cliby Sent: Friday, January 23, 2009 4:08 PM To: 'Crestron@...' Subject: RE: [Crestron] Re: Question on finding the number of defined array elements. Isn't' that why you pass strings by reference unless you have a good reason for passing them by value (or you're dealing with one of the S+ quirks that won't allow a passing byref, like IIRC, a serial input)? Or would pointers open up another advantageous option that I'm forgetting at the moment (it's been far too long since the last time I played with a language the formally supported pointers :(... but they are uber cool. Took me most of my first semester of AP CompSci in high school to figure the point out, but after that... wow!) Lincoln -- Lincoln King-Cliby, CTS Applications Engineer ControlWorks Consulting, LLC V: 440.729.4640 x1107 F: 440.729.0884 I: Crestron Authorized Independent Programmer -----Original Message----- From: Crestron@... [mailto:Crestron@...] On Behalf Of Chris Erskine Sent: Friday, January 23, 2009 11:12 AM To: Crestron@... Subject: RE: [Crestron] Re: Question on finding the number of defined array elements. 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@...> ------------------------------------ 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 ------------------------------------ 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 ------------------------------------ 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 |
Isn't' that why you pass strings by reference unless you have a good reason for passing them by value (or you're dealing with one of the S+ quirks that won't allow a passing byref, like IIRC, a serial input)?
toggle quoted message
Show quoted text
Or would pointers open up another advantageous option that I'm forgetting at the moment (it's been far too long since the last time I played with a language the formally supported pointers :(... but they are uber cool. Took me most of my first semester of AP CompSci in high school to figure the point out, but after that... wow!) Lincoln -- Lincoln King-Cliby, CTS Applications Engineer ControlWorks Consulting, LLC V: 440.729.4640 x1107 F: 440.729.0884 I: Crestron Authorized Independent Programmer -----Original Message-----
From: Crestron@... [mailto:Crestron@...] On Behalf Of Chris Erskine Sent: Friday, January 23, 2009 11:12 AM To: Crestron@... Subject: RE: [Crestron] Re: Question on finding the number of defined array elements. 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@...> ------------------------------------ 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 ------------------------------------ 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 |
That that is almost exactly what came out of conversation I had with someone fairly high up in the software world of things an Infocomm or two ago, and also the difficulty of protecting the relative "sandbox" that SIMPL+ plays in.
toggle quoted message
Show quoted text
Lincoln -- Lincoln King-Cliby, CTS Applications Engineer ControlWorks Consulting, LLC V: 440.729.4640 x1107 F: 440.729.0884 I: Crestron Authorized Independent Programmer -----Original Message-----
From: Crestron@... [mailto:Crestron@...] On Behalf Of fooguy89 Sent: Friday, January 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: point of view; it just doesn't do what you want/expectcode copies a NULL-terminated string, where 'p' points to the destination and'q' points to the source:. The while() terminates when the NULL terminatingbyte is hit. semi-colon
------------------------------------ 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 |
Well, even if you pass your array ByRef, *every* time you access an
toggle quoted message
Show quoted text
array element, bounds checking is done. I think that speed hit, whatever it amounts to being in their implementation, outweighs finding an array overrun. As all of us who have programmed in C know, just because you overrun the array "now" doesn't mean you find the error now. You could run into the after effect minutes, days, or years from the time it happened! --- In Crestron@..., "Oliver Hall" <oliver.hall@...> wrote:
|
Chip Moody
That seems pretty legit - thanks Jeremy.
Of course, now I just feel guilty that I'm wasting an extra 1k of volatile memory in my module... :) - Chip --- In Crestron@..., Jeremy Weatherford <xidus.net@...> wrote: on this.
the Database area. Yahoo! Groups Links
|
Well, in the case of something like C, bad pointer arithmetic and bad
indices of arrays are just as bad. At least with SIMPL+ arrays, sure you should check your indices to make sure that you're doing the right thing, but if you over/underrun, at least you don't write into other application memory, it issues an error and you can later try to track it down. --- In Crestron@..., Jeremy Weatherford <xidus.net@...> wrote: 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. |
Jeremy Weatherford
The result of mid() seems to get stored in a temporary variable even
toggle quoted message
Show quoted text
if you just assign it to a local variable. Here's an example from Crestron's BKParser.usp, line 245: Temp1$ = Mid(Temp$[4], 2, (Temp[4] -2)); //Get Name string And here's what it compiles to: UpdateSourceCodeLine( INSTANCE_PTR( S2_BKParser ), 245 ); FormatString ( INSTANCE_PTR( S2_BKParser ) , LOCAL_STRING_STRUCT( __FN_DST_STR__1 ) ,2 , "%s" , Mid ( LOCAL_STRING_STRUCT( __FN_DST_STR__ ) , GetStringArrayElement ( INSTANCE_PTR( S2_BKParser ), LOCAL_STRING_ARRAY( __TEMP$ ) , 4 ) , 2, (GET_LOCAL_INTARRAY_VALUE( S2_BKParser, __TEMP, 0, 4 ) - 2)) ) ; FormatString ( INSTANCE_PTR( S2_BKParser ) , LOCAL_STRING_STRUCT( __TEMP1$ ) ,2 , "%s" , __FN_DST_STR__1 ) ; In this case, there's a temporary variable named __FN_DST_STR__1 used for the result of Mid(). I seem to remember seeing string overflow error messages for variables with names like that. I'm guessing they're generated for any kind of string expression, although it seems odd to use it for a simple assignment. Generated code is never the paragon of efficiency, though... Jeremy On Fri, Jan 23, 2009 at 11:53 AM, Chip Moody <cfm@...> wrote:
--
Jeremy Weatherford |
Matt
Touche
the Iend of an IF statement. Idon't mess up the execution order/nesting. (Didn't see the ; -fatal,but a trace should have shown 10 outputs rather than just 1.) thewereto remove the trace statement, could you use no brackets? If helpbrackets are required, I guess there's another error in the lookingfile. ().toassigneddetermine the number of elements a string array has beeninSimpl. Looking at S+ I see the directive isSignalDefined symbol,Ihavethe following code (not complete). butincorrect?NumSources always = 10, I was expecting to see 1. |
Chip Moody
That was a potential guess for me, but I didn't know if it was one
of those "iffy" situations in the S+ compiler that might bite me in the ass down the road, y'know? Maybe I'll get off my butt and see what happens if I change it over the weekend... - Chip P.S. Oliver - thanks for your answer too, and enjoy the beer!! --- In Crestron@..., "Joseph K. Vossen" <jkv@...> wrote: compiler, but all of the compilers I have worked on will generate a "temporary" whose type/size is "local" to the block and is used to hold the value for cases like this. The temporary is generated on the stack so it will "disappear" when you go out of scope. You can't reference it directly (by name) since it is typically generated above/below (depends on how the stack frame is maintained) the variables that the programmer declared for that block.
|
Joseph K. Vossen
[snip]
My mindset was that the result of MID doesn't exist as a variable,well, actually it does. I can't say for certain with the SIMPL+ compiler, but all of the compilers I have worked on will generate a "temporary" whose type/size is "local" to the block and is used to hold the value for cases like this. The temporary is generated on the stack so it will "disappear" when you go out of scope. You can't reference it directly (by name) since it is typically generated above/below (depends on how the stack frame is maintained) the variables that the programmer declared for that block. [more snip] |
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: XM Now Playing module, and just couldn't bring myself to write TBTS onthis. to one of my own functions that in turn manipulates the results of thethis: I show in that snippet up there. So in the ACTUAL module, one of thefunction for that matter) exist in some malleable state that I can operateon? of ByRef does actually make a copy the data 8) |
to navigate to use esc to dismiss