Simple Crc Program In C

0 views
Skip to first unread message

Gianira Jardin

unread,
Jul 26, 2024, 3:35:39 AM7/26/24
to mmethydrachee

C is a structured, high-level, and general-purpose programming language, developed in the early 1970s by Dennis Ritchie at Bell Labs. C language is considered as the mother language of all modern programming languages, widely used for developing system software, embedded software, and application software.


Note: The Event participant source supports all events configured in the Events Framework, including PX custom events. Using Event as a source in Simple Programs, admins can take the following actions:

You can view the list of all people who were not added as program participants for any reason. To view these records, click the Failed Participants tab. After participants are synced (manually or via schedule), the list is generated, and after uniqueness criteria and advanced criteria are applied.

In MC15 the only ways to terminate a conditional block is with either an "otherwise", or a line with no conditional statement in it. Since the only conditional statements available are "if" and "otherwise", there had to be a choice between evaluating all consecutive if statements, or exiting the block when any one was true. I guess it was decided the lesser of two evils was to evaluate all of them (a decision I personally agree with). Since the "otherwise" is only meant as a trap when none of the conditions are met, in my opinion it is logical that it is not evaluated unless none of the conditions are met. So your test1 program has two conditional blocks, but your test2 program has only one. It's made even more confusing by the fact that you don't have a return statement on the first line. It means that in test1 the line actually has no effect at all.

You are not the first person to be confused by this behavior (surprise!). Even if you know how it works, it can also make it hard to figure out what a program will actually do. It's also rather limiting, because sometimes what you want is an "else if" or case statement, but that is not easy to create in MC15. Hence the changes in Prime. There are things I don't like about Prime, but IMHO the new conditional structure is a huge improvement.

Converting the worksheet in Prime2 format shed a little light on the phenomenon but I'm still lacking full understanding. Changing that "also if" to a simple "if" does what I want, but how can I achieve this in Mathcad15 without inserting that dummy line?

In the following, M15 does exactly what I expect, and even though I am not a fan of the current M1x or MP programming metaphor, both are OK for what they do: M1x is not complete enough and requires those extra "" lines to clean up the logic, and MP's lines are superfluous when single lines suffice (and I prefer them).

After some more investigation (RTFM, aka Mathcad help) it seems that this behaviour is implemented on purpose and I guess the only way to deal with it is to add an extra line - either the dummy I had inserted or a dummy "otherwise" statement after the first if.

As Mona wrote in a thread last year ( ) the "also if" was introduced in Prime2 for backwards compatibility. In Prime a sequence of if-statements before an otherwise-statement evaluates the way I expected it to do in MC15.

In MC15 the only ways to terminate a conditional block is with either an "otherwise", or a line with no conditional statement in it. Since the only conditional statements available are "if" and "otherwise", there had to be a choice between evaluating all consecutive if statements, or exiting the block when any one was true. I guess it was decided the lesser of two evils was to evaluate all of them (a decision I personally agree with).

I was assuming that mathcad would behave like any other programming language which only offer if and else: if an if-statement is not followed by an else it is finished. If you want a cascading evaluation you would have to put the second if in the else (otherwise) branch. MC 15 behaves differently - good to know (hope i will remember).

You are talking of the "XXX" line. In the "real" program I was workin on there is some kind of evaluation there, a loop if i remember correct. I tried to track down the problem and simplified it as much as possible which helped me to find out what was going on. So i found that the first if (which had nothing to do with the last one) was responsible for the troubles.

Yeeess, it is an improvement structurally but I have to confess to preferring the more compact one line structure (that I know others don't) and "otherwise" as opposed to "else" ... I think there's a little to much "programmer" mentality about Prime and not enough "mathematician" or "engineer".

I wrote a worksheet that contained a 'piecewise' function that attempted to emulate this pattern ... worked better in M11 due to lack of SUC. However, I can't find it, so the attached will have to do.

I'm still stuck at the first part thinking what logic I am missing as of the difference between the two definitions of f(x), one without, the other with return and why the evaluation of the if sequence is different because of this. After reading the help and Richards explanations I thought I understand the way MC15 deals with if-sequences - a mistake

Assuming that I've interpreted you correctly, the evaluation has nothing to do with the lack of a return statement in the first line (ie, x>1). It is purely to do with the if-otherwise statements being contiguous.

In version 2, Mathcad notes that it has moved straight on to another if statement, but keeps track of the fact that it either has, or has not, determined x>1 to be true. If it was true, then Matchad retains "XXXX" as the last calculated value.

Yes, exactly. The program exits, returning the value of the expression that is the argument to the return statement. That's what I was alluding to when I said that the first line of your program not having a return statement makes it even more confusing. If it did, then if x>1 the program would return "XXX", and the second if statement would never even be evaluated.

Within programs, I don't have a problem with it. I don't believe you can ever make programs look like anything other than programs (at least, not if you want to retain any real flexibility), so switching to programmer mentality is fine with me. In then end it's less confusing to most people. Anyway, any mathematician or engineer that doesn't know what "else if" means in a program, and even if they don't know can't figure it out, should be thrown into the boiling hell of a liberal arts collage until they have redeemed themselves

Within programs, I don't have a problem with it. I don't believe you can ever make programs look like anything other than programs (at least, not if you want to retain any real flexibility), so switching to programmer mentality is fine with me. In then end it's less confusing to most people.

It depends how you define program. I've also suggested options (eg, subworksheets) for creating program together with worksheet looping mechanisms. Many people seem happy with laying out a worksheet on a region-by-region basis, at least if the number of times we end up suggesting that such implementations be wrapped up into a function is anything to go by!

Anyway, any mathematician or engineer that doesn't know what "else if" means in a program, and even if they don't know can't figure it out, should be thrown into the boiling hell of a liberal arts collage until they have redeemed themselves

Since this is a "very small simple and useful program" (e.g. someone could recreate it easily), I would not worry too much about the details and choose a simple license, something you can include in about 20 lines at the top of every file:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Reply all
Reply to author
Forward
0 new messages