Heater
Posts: 13081
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sun Jul 21, 2019 10:09 pm

DavidS,
If you write a function definition as:

Code: Select all

CalcPosErr(...);
I'm almost certain you will put a comment on it like:

Code: Select all

// Calculate position error
At which point you have moved valuable information from something the compiler can check to a comment which it does not.

At which point you have not saved typing any characters. You have actually typed more. Most of then uncheckable.

I reject the notion that "calculatePostionError" is more unreadable because it is more than 12 characters.

As for typos, any modern editor is already underlining them with red squiggles as you type. And/or offering the correct spelling. And the compiler/interpreter will find them soon enough if not. Hardly a reason to mangle variable and function names.

By the way, I thought you hated name mangling in C++ compilers.

jahboater
Posts: 4598
Joined: Wed Feb 04, 2015 6:38 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Sun Jul 21, 2019 11:27 pm

PeterO wrote:
Sun Jul 21, 2019 10:56 am
On modern machines I rarely add more that a dozen lines of code without testing.
Sensible. Then, if things break, its easy to find the change that caused the problem.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 12:57 am

jahboater wrote:
Sun Jul 21, 2019 11:27 pm
PeterO wrote:
Sun Jul 21, 2019 10:56 am
On modern machines I rarely add more that a dozen lines of code without testing.
Sensible. Then, if things break, its easy to find the change that caused the problem.
So long as it is not a bug somewhere else in the code from a missed sanity check or bounds check that just did not show up until then.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 1:05 am

Heater wrote:
Sun Jul 21, 2019 10:09 pm
DavidS,
If you write a function definition as:

Code: Select all

CalcPosErr(...);
I'm almost certain you will put a comment on it like:

Code: Select all

// Calculate position error
And you would be wrong on that. If there is a need to explain parameters I will put a comment to that effect, though why repeat the name that is already clearly readable?
At which point you have moved valuable information from something the compiler can check to a comment which it does not.

At which point you have not saved typing any characters. You have actually typed more. Most of then uncheckable.
Wrong, as no such comment would exist. The name is clearly readable without the comment.
I reject the notion that "calculatePostionError" is more unreadable because it is more than 12 characters.
Read what I said again. It also increases the probability of typing errors.
As for typos, any modern editor is already underlining them with red squiggles as you type. And/or offering the correct spelling. And the compiler/interpreter will find them soon enough if not. Hardly a reason to mangle variable and function names.
Really. So let us waste compile time to find typos. Sounds like a good use of resources. That must be the philosophy of those programmers that will only produce 10 lines of code per day during an active project that you talk about. That would be a productivity killer.

I prefer to attempt to verify my code as much as I can before it is compiled. It reduces the number of re compiles before something usable comes about. Lets not use the compiler as a typo checker (usually [we all miss something from time to time]). Lets at least pretend to take pride in our work.
By the way, I thought you hated name mangling in C++ compilers.
Hence why I agree with using clearly readable names in code, like I illustrated above.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

Heater
Posts: 13081
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 4:34 am

DavidS,

OK. All the code you write is perfectly clear to you. We will never know how well it reads for the rest of us because as far as I can tell you have never shown any here.

As for that 10 lines of code per day thing. It's not something I pulled out of thin air. It's something that as been measured many times. I'm pretty certain it applies to you as well.

About that C++ name mangling thing...

You have suggested there should be some other way for compilers to do this. Something about "modern objects" which I did not follow. My question is:

When you see some assembler output from a compiler that has mangled names, what exactly is it you would like to see in that assembler listing instead? Can you give an example?

So for example, GCC might output this with mangled names:

Code: Select all

62d:   e8 1b 00 00 00          callq  64d <_Z3addIiET_S0_S0_>
Which we can easily view with demangled names by using "objdump -C" like this:

Code: Select all

62d:   e8 1b 00 00 00          callq  64d <double add<double>(double, double)>
What would you rather see there?

Clearly all the information the linker needs to do it's job is encoded into the mangled name string. What do you suggest is missing?

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 5:03 am

Heater wrote:
Mon Jul 22, 2019 4:34 am
DavidS,

OK. All the code you write is perfectly clear to you. We will never know how well it reads for the rest of us because as far as I can tell you have never shown any here.
If you say so.

I do admit that since you have been hanging out I have posted a lot less code than I did before then. I even had began a series of tutorials on assembly language programming, that got cut short by a combination of a negitive commenter and me being in the hospital. There were many other areas I had posted code in these forums before that. Many fewer since.
As for that 10 lines of code per day thing. It's not something I pulled out of thin air. It's something that as been measured many times. I'm pretty certain it applies to you as well.
I guess that depends on what you are actually measuring. If measuring total code produced per active day of coding, I would strongly dissagree of it applying to me.

If you are measuring the difference in lost code to gained code as things are better optimized and debuged, then maybe it would apply to me (and other programmers). In that case it is often possible to find a negitive number of lines of code per day, as optimizing algorithms often reduces code.

And I am more consertive in how I count lines of code than most (I do not count a lot of the lines others do as code).
About that C++ name mangling thing...

You have suggested there should be some other way for compilers to do this. Something about "modern objects" which I did not follow. My question is:

When you see some assembler output from a compiler that has mangled names, what exactly is it you would like to see in that assembler listing instead? Can you give an example?

So for example, GCC might output this with mangled names:

Code: Select all

62d:   e8 1b 00 00 00          callq  64d <_Z3addIiET_S0_S0_>
Which we can easily view with demangled names by using "objdump -C" like this:

Code: Select all

62d:   e8 1b 00 00 00          callq  64d <double add<double>(double, double)>
What would you rather see there?

Clearly all the information the linker needs to do it's job is encoded into the mangled name string. What do you suggest is missing?
And how would that linker take advantage of object formats that support non-mangled type specific naming, as well as object locality (like most versions of COFF)?
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
bensimmo
Posts: 4152
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 6:41 am

One problem with
CalcPosErr
Is Calculate Positive Error, as I read it, is not what you are doing. (That is truthfully how i read it even after reading the posts before).

You would need a comment or I would have to work out from the context of the code what it is for.

Also if you read in a foreign language, it must be a pain to translated.

With modern IDEs is typing long words that hard? Auto-completion, variable usage highlighting, ..., it is checking as you go along.

Heater
Posts: 13081
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 7:08 am

DavidS,
I guess that depends on what you are actually measuring. If measuring total code produced per active day of coding, I would strongly dissagree of it applying to me.
The measurements are pretty well know in software circles by now, you must have heard of Fred Brooks and "The Mythical Man Month"?

It's a measurement form the point of view of a corporation. That corporation has a bunch of programmers on the payroll. They get large projects done using large teams over years. That corporation knows how long a project took, how many man hours they had to pay for, all the way from concept through requirements capture, design, coding, testing, debugging, documenting, fixing issues as users report them after deployment, etc, etc. At the end of all that they can count how many lines of source code there is in the project. And there comes the result: Of the order of 10 lines of source code per programmer per day.

Don't forget that corporation is paying for holidays, sick days, training, all that endless time at meetings etc, etc. A project does not start and end with just coding, it's about the whole project life cycle.

Anecdote time:

I was once contracted for a year to fix bugs in a large project. The team of six or so was feverishly working on a new release, so I was hired to do the dirty work. Well, for a start I knew nothing about that code base and it took an age to find my way around it. Fixing a bug required understanding the bug report, reproducing the bug reliably, possibly needing a chat with the customer to find out what they had really done, then finding where the bug is in the code and figuring out how the hell it was supposed to be working and fixing it. Then retesting all that.

If I got one bug fixed in a day that was good. Often a bug fix turned out to require a one line or even one character change!

Well of course my contribution to the project for a year was probably zero lines of code added to the final count. Which of course drags the average down for the whole team.
And how would that linker take advantage of object formats that support non-mangled type specific naming, as well as object locality (like most versions of COFF)?
I don't really have much of an idea about object file formats. Wikipedia tells me that the COFF standard is inadequate to do what we want to do so I don't know why you are suggesting it.

But that was not my question, I was asking what you want to see in the assembler listing output as shown in the the example above.

Heater
Posts: 13081
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 7:20 am

bensimmo,

Exactly. It's unnecessarily cryptic and obscuring.

There is no need to save keystrokes, when you can only produce in the order of ten lines of code per day you have time to type it!

User avatar
PeterO
Posts: 4940
Joined: Sun Jul 22, 2012 4:14 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 10:53 am

Heater wrote:
Mon Jul 22, 2019 7:08 am
The measurements are pretty well know in software circles by now, you must have heard of Fred Brooks and "The Mythical Man Month"?
But that was not my question, I was asking what you want to see in the assembler listing output as shown in the the example above.
I could never understand why this was called "The Mythical Man Moth" until I actutaly came across a copy :lol:
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Heater
Posts: 13081
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 11:05 am

I am Mythical Man.

It's often rumored that I do work some place. But nobody has ever seen any evidence of it.

User avatar
PeterO
Posts: 4940
Joined: Sun Jul 22, 2012 4:14 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 11:09 am

Heater wrote:
Mon Jul 22, 2019 11:05 am
I am Mythical Man.

It's often rumored that I do work some place. But nobody has ever seen any evidence of it.
You are DavidS and I claim my £5 :-)
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
kennyc
Posts: 74
Joined: Mon Jul 15, 2019 9:26 am

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 11:27 am

And What about LISP!!! Yes!! That's the Best!
:)
Kenny A. Chaffin
Blog: http://mansionsofthemind.blogspot.com/
Art: https://www.deviantart.com/kennyc
"Strive on with Awareness" - Siddhartha Gautama

User avatar
Michiel O.
Posts: 178
Joined: Mon Dec 12, 2016 12:06 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 12:16 pm

Why do you think lisp is the best? I can imagine not having to worry anymore about some nasty concurrency problems when using clojure, but that's more due to software transactional memory than due to homoiconicity between program code and data, I suspect.

PS. If you want to toy with a lisp that has perfect interop with Python, give hy a try. Sorry, that rhymes :mrgreen:
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes

Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 12:21 pm

DavidS wrote:
Mon Jul 22, 2019 1:05 am
Heater wrote:
Sun Jul 21, 2019 10:09 pm
DavidS,
If you write a function definition as:

Code: Select all

CalcPosErr(...);
I'm almost certain you will put a comment on it like:

Code: Select all

// Calculate position error
And you would be wrong on that. If there is a need to explain parameters I will put a comment to that effect, though why repeat the name that is already clearly readable?
At which point you have moved valuable information from something the compiler can check to a comment which it does not.

At which point you have not saved typing any characters. You have actually typed more. Most of then uncheckable.
Wrong, as no such comment would exist. The name is clearly readable without the comment.
I reject the notion that "calculatePostionError" is more unreadable because it is more than 12 characters.
Read what I said again. It also increases the probability of typing errors.
As for typos, any modern editor is already underlining them with red squiggles as you type. And/or offering the correct spelling. And the compiler/interpreter will find them soon enough if not. Hardly a reason to mangle variable and function names.
Really. So let us waste compile time to find typos. Sounds like a good use of resources. That must be the philosophy of those programmers that will only produce 10 lines of code per day during an active project that you talk about. That would be a productivity killer.

I prefer to attempt to verify my code as much as I can before it is compiled. It reduces the number of re compiles before something usable comes about. Lets not use the compiler as a typo checker (usually [we all miss something from time to time]). Lets at least pretend to take pride in our work.
By the way, I thought you hated name mangling in C++ compilers.
Hence why I agree with using clearly readable names in code, like I illustrated above.

I heard that some institutions write now just 3 lines of code:

After that USA fu-p with one satellite which dropped because they used both imperial and European numbers in team.
Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

Heater
Posts: 13081
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 1:07 pm

Yeah, and I keep reading all over the place that good 50% of software projects fail and get cancelled or go unused.

Figuring that in we are down to about 1 line of code per software engineer per day that actually ends up doing anything useful.

For example:
https://www.zdnet.com/article/study-68- ... ects-fail/

Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 2:41 pm

This also co-explains why is so popular Java as its very readable code... You write more, but man, you will be happy when you edit it again back in 5 years!

Also you can use "var" as C#, so


var s = new String();

Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

pister
Posts: 24
Joined: Thu Jun 21, 2018 5:24 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 3:29 pm

HI. I am not 100% sure but I don't think it's anything to do with speed or complexity, but the fact that it requires less work on the admins part. To stop the students from installing apps, they just stop all installs. It is then very difficult to make an exception for when c compiles. However, a language like python with a interpreter is much easier as they just install the interpreter. I believe the most common in schools is MU.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 4:23 pm

It's a measurement form the point of view of a corporation. That corporation has a bunch of programmers on the payroll. They get large projects done using large teams over years. That corporation knows how long a project took, how many man hours they had to pay for, all the way from concept through requirements capture, design, coding, testing, debugging, documenting, fixing issues as users report them after deployment, etc, etc. At the end of all that they can count how many lines of source code there is in the project. And there comes the result: Of the order of 10 lines of source code per programmer per day.
I figured that the measure would be something like that, and it shows the difference in the view. That measure is so far off it is not even funny. Though it is like you to go with that over-publicized metric.

You see while these Software Engineers working at said corporations are writing code that contributes to a very large project most will have little side projects (small things that are of much less note, often one man un-planned mini-projects) that are contributing code to the base of the company and not being counted in that kind of metric.

Also it does not count for a huge number of lines of code written that get completely replaced with new code (adding even more lines of code) at a later time. A project with 5000 lines of code in the final "Gold" release will often have had more than 30000 lines of code written for it between inception and the final release of the first "Gold" or release Version.

Then there is the fact that every programmer I know writes code at home for personal and or fun projects, that has nothing to do with the company. Thus that is more lines of code being produced by that programmer that are not counted.

Then you have programmers, that while they may be programmers, are not contributing any actual code to a given project (as they are instead working on data tables or the like). This lowers the total number per programmer.

So I will agree that the number of lines of code that make it to the final product as counted per project per programmer may be less than 10, assuming it is an average. Though that is only per project, and only lines of code that survive until release.
Last edited by DavidS on Mon Jul 22, 2019 4:31 pm, edited 1 time in total.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

Heater
Posts: 13081
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 4:27 pm

If that is true I'm appalled because:

1) Computers are for running programs. That includes programs compiled to binary.

2) To run a program compiled from C (or anything else) one does need need to "install an app" anymore than running code with an interpreter.

3) That code being run from an interpreter has all the same permissions as any native compiled code. It does not make anything safer or even more convenient.

If that is true said administrators are dangerously dim.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 4:33 pm

Heater wrote:
Mon Jul 22, 2019 4:27 pm
If that is true I'm appalled because:

If that is true said administrators are dangerously dim.
I feel they are now days. How long has it been since you have audited what they consider to be an appropriate standard of education.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

Heater
Posts: 13081
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 4:48 pm

DavidS,
I figured that the measure would be something like that, and it shows the difference in the view. That measure is so far off it is not even funny. Though it is like you to go with that over-publicized metric.
So far "off" what? It is what it is, and if you are paying for code then that might be interesting to you.
You see while these Software Engineers working at said corporations are writing code that contributes to a very large project most will have little side projects (small things that are of much less note, often one man un-planned mini-projects) that are contributing code to the base of the company and not being counted in that kind of metric.
That is accounted for. If you ever worked at a serious company you will know they have their engineers fill in time sheets and hours get assigned to projects.
Also it does not count for a huge number of lines of code written that get completely replaced with new code (
That of course is totally irrelevant. Think of it like building a house. If you have to tear it down and rebuild it because you got the design wrong you can't then claim to have built two houses in that time.
Then there is the fact that every programmer I know writes code at home for personal and or fun projects, that has nothing to do with the company. Thus that is more lines of code being produced by that programmer that are not counted.
That of course is totally irrelevant. It does not contribute to the project and the company is not paying for it. It's also being done during time above and beyond the time being counted, i.e. a normal working day of 8 hours or whatever.
Then you have programmers, that while they may be programmers, are not contributing any actual code to a given project (as they are instead working on data tables or the like). This lowers the total number per programmer.
That of course is totally irrelevant. They are your software employees, you are paying for them. If those supposed tables are essential to the products function then time spent on that can reasonably be included.
So I will agree that the number of lines of code that make it to the final product as counted per project per programmer may be less than 10, assuming it is an average. Though that is only per project.
Good. So what was all the above about? Nothing.

Heater
Posts: 13081
Joined: Tue Jul 17, 2012 3:02 pm

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 4:58 pm

DavidS,
I feel they are now days. How long has it been since you have audited what they consider to be an appropriate standard of education.
Why never of course. I am in no position to audit any such thing.

I do worry about what I hear about schools and education all the time. Especially in the USA.

On the other hand I do from time to time meet smart young guys who seem to have come out of it OK.

I have met a number of teachers that were very depressed about the system they find themselves in. Some of which eventually quit even if teaching was the thing they wanted to do.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 5:17 pm

@Heater:

As I stated in another thread today, a big part of the reason that I stopped posting code on forums is that people will spit on the code because I use a lot of assembly. They do not bother to look at the code, or attempt to see how it works, no they just spit on the code because of the assembly language usage.

If people dislike Assembly language that is alright. Everyone has languages they dislike. If people have a problem with my code that is alright, though say so.

The trouble is in people openly spiting on my code because I chose to use assembly language, and nothing to do with the code itself.

As an example the most recent code of use I posted of my own written in C with some assembly language vaneers (a simple example of WIMP programming on RISC OS):

main.c

Code: Select all


#include "MWimp.h"

long TBlock[255], WData[255], *WDataTop;
long THandle;
long WindowH[2];
long BarIconH;
long Quit = 0;
CIconBlock BarIcon = {-1,0,0,68,68,0x3002,{"!c02wimp"}};
NewMenu("Wimp Tut 0",Menu0,2)


//**************************************************************************
char *StrCpy(char *s, char *t){
  for(int cnt = 0; (s[cnt] = t[cnt]); cnt++);
  return s;
}


//**************************************************************************
void MClick(void){
  if (TBlock[3] == -2){
      switch (TBlock[2]){
        case 1: break;
        case 2: Wimp_CreateMenu(&Menu0,(TBlock[0] - 64),188);break;
        case 4: TBlock[0] = WindowH[0];
                Wimp_GetWindowState(TBlock);
                Wimp_OpenWindow(TBlock); break;
    }
  } else if (TBlock[3] == WindowH[0]){
      switch (TBlock[2]){
        case 2: Wimp_CreateMenu(&Menu0,(TBlock[0] - 64), TBlock[1]); break;
      }
  }
}


//**************************************************************************
void SelMenu(void){
  //unsigned long tmpx, tmpy;
  switch (*TBlock){
    case 0: TBlock[0] = WindowH[1];
            Wimp_GetWindowState(TBlock);
            //tmpx=TBlock[3] - TBlock[1];
            //tmpy=TBlock[4] - TBlock[2];
            Wimp_OpenWindow(TBlock); break;
    case 1: Quit=0x0f; break;
   }

}


//**************************************************************************
void PollLp(void){
  while (!Quit){
  long r = Wimp_Poll(0x2301,TBlock,(long *)0);
    switch(r){
     case 2: Wimp_OpenWindow(TBlock); break;
     case 3: Wimp_CloseWindow(TBlock); break;
     case 6: MClick(); break;
     case 9: SelMenu();
       break;
     case 17:
     case 18:
      if (TBlock[4] == 0) Quit = 0x0f;
      break;
    }
  }
}


//**************************************************************************
void CleanUp(void){
  Wimp_CloseDown(THandle,0x4b534154);
  return;
}


//**************************************************************************
int main(void){
  THandle = Wimp_Initialise(310,0x4B534154,"Wimp 2",(long *)0);

  BarIconH = Wimp_CreateIcon(0,&BarIcon);

  if(Wimp_OpenTemplate("<C00Wimp$Dir>.Templates") == -1) {return 0;}
  long *toff;
  if (!(toff=Wimp_LoadTemplate(TBlock,WData,WData+64,"main\0"))) {
    CleanUp(); return 0;
  }
  WindowH[0] = Wimp_CreateWindow(TBlock);

  if (!Wimp_LoadTemplate(TBlock,toff,WData+256,"info\0")) {
    CleanUp(); return 0;
  }
  WindowH[1] = Wimp_CreateWindow(TBlock);
  if(Wimp_CloseTemplate() == -1){return 0;}

  Menu0.i[0].f = 0;
  Menu0.i[0].sub = WindowH[1];
  Menu0.i[0].icf = 0x07000021;
  Menu0.i[1].f = 0x80;
  Menu0.i[1].sub = -1;
  Menu0.i[1].icf = 0x07000021;
  StrCpy(Menu0.i[0].name, "Info...\0");
  StrCpy(Menu0.i[1].name,"Quit\0");

  PollLp();

  CleanUp();
  return 0;
}
MWimp.h

Code: Select all

#ifndef __MWimp_h__
#define __MWimp_h__

/*** Definition of a Menu Item ***/
typedef struct {
  long f;            //Item menu Flags.
  long sub;          //SubMenu.
  long icf;          //Item IconFlags.
  char name[12];     //Item name.
} MENITEM;

/*** Menu Block. ***/
typedef struct {
  char ttl[12];      //Menu Title.
  char tfc;          //Title Foreground colour.
  char tbc;          //Title Background colour.
  char wfc;          //Work forground colour.
  char wbc;          //Work background colour.
  long w;            //Width of items.
  long h;            //Height of items.
  long vg;           //Gap.
}MENU;

#define NewMenu(ttl,name,cnt) struct{MENU m; MENITEM i[cnt];} name ={{ttl,7,2,7,0,96,44,0}};

typedef struct {
  long x0,y0,x1,y1;  //Coords of bottom left of Icon.
  long flags;        //Icon Flags.
  union {            //Data, in one of two forms.
   char txt[12];     //Short name or short text.
   struct {          //Or inderected:
    void *data[2];   //Pointers to data, depending on flags.
    long v;          //Buffer length or sprite pointer value.
   }i;
  }d;
}IconBlock;

typedef struct {
  long Win;          //Window handle to put Icon in.
  long x0,y0,x1,y1;  //Coords of bottom left of Icon.
  long flags;        //Icon Flags.
  union {
   char txt[12];     //Short sprite name or short text depending on flags.
   struct {          //OR:
    void *data[2];   //Pointers to data, as per flags.
    long v;          //Value of buffer length or sprite pointer.
   }i;
  }d;
}CIconBlock;

typedef struct {
  long x,y,x2,y2;    //Window bounds coords.
  long scx,scy;      //Scroll offsets.
  long BHndl;        //Handle to open behind.
  long flags;        //Window Flags.
  char TFCol;        //Colour for title forground and frame.
  char TBcol;        //Title background colour.
  char WFcol;        //Work area foreground colour.
  char WBCol;        //Background of work area colour.
  char SBCol;        //Foreground colour for Scrollbar.
  char SFCol;        //Scorllbar foreground colour.
  char FTBCol;       //Title background color whith input focus.
  char EFlags;       //Extra flags.
  long Wx,Wy,Wx2,Wy2;//Work area bounds.
  long TIcnF;        //Icon flags for window title.
  long WBtnF;        //Button flags for work area.
  long SprBlk;       //Sprite area control block.
  long MinB;         //Min width in high 16 bits, min height in low 16 bits.
    union {
   char txt[12];     //Short text depending on flags.
   struct {          //OR:
    void *data[2];   //Pointers inderected to data, as per TIcnF flags.
    long v;          //Value of buffer length or sprite pointer.
   }i;
  }ttl;
  long IcnCnt;       //Number of icons in window definition.
} WinBlock;

//Block to use with Wimp_OpenWindow.
typedef struct {
  long WinH;         //Window Handle.
  long x,y,x2,y2;    //Window bounds coords.
  long scx,scy;      //Scroll offsets.
  long BHndl;        //Handle to open behind.
} OWinBlock;

/*** The functions to call simple WIMP SWI's ***/
long Wimp_Initialise(long ver, long magic, char *name, long *msglist);
long Wimp_CloseDown(long thandle, long magic);
long Wimp_CreateIcon(long np, CIconBlock *icn);
long Wimp_Poll(long Mask, void *block, long *pw);
long Wimp_PollIdle(long Mask, void *block, long rtime);
long Wimp_CreateMenu(void *m,long x, long y);

long Wimp_OpenTemplate(char *FileName);
long *Wimp_LoadTemplate(long *buff, long *ind, long *endind, char *Tname);
long Wimp_CloseTemplate(void);
long Wimp_CreateWindow(long *buff);
long Wimp_CloseWindow(long *buff);
long Wimp_OpenWindow(long *buff);
long Wimp_GetWindowState(long *buff);

#endif
Wimp.s

Code: Select all


  AREA |main|, CODE, READONLY
  ENTRY
  EXPORT Wimp_Initialise, Wimp_CloseDown, Wimp_CreateIcon
  EXPORT Wimp_Poll, Wimp_PollIdle, Wimp_CreateMenu
  EXPORT Wimp_CreateWindow, Wimp_OpenWindow, Wimp_CloseWindow
  EXPORT Wimp_OpenTemplate, Wimp_LoadTemplate, Wimp_CloseTemplate
  EXPORT TemplateFontRef, Wimp_GetWindowState

Wimp_Initialise
  SWI   &600C0     ;SWI XWimp_Initialise.
  MOVVC R0,R1      ;Return task handle.
  MOVVS R0,#0      ;Null on error.
  MOV   R15,R14

Wimp_CloseDown
  SWI   &600DD     ;SWI "XWimp_CloseDown"
  MOVVS R0,#-1     ;If error return -1.
  MOV   R15,R14

Wimp_CreateIcon
  SWI   &600C2     ;SWI "XWimp_CreateIcon"
  MOVVS R0,#0      ;On error return 0.
  MOV   R15,R14

Wimp_CreateMenu
  MOV   R3,R2      ;Addjust parameters passed in from C.
  MOV   R2,R1
  MOV   R1,R0
  SWI   &600D4     ;SWI "XWimp_CreateMenu"
  MOVVS R0, #-1    ;Return -1 on error.
  MOV   R15,R15

Wimp_Poll
  SWI   &600C7     ;SWI "XWimp_Poll"
  MOVVS R0, #-1    ;On error return -1.
  MOV   R15,R14

Wimp_PollIdle
  SWI   &600E1     ;SWI "XWimp_PollIdle"
  MOVVS R0, #-1    ;On error return -1.
  MOV   R15,R14

Wimp_CreateWindow
  MOV   R1,R0
  SWI   &400C1     ;SWI "Wimp_CreateWindow"
  MOV   R15,R14

Wimp_GetWindowState
  MOV   R1,R0
  SWI   &600CB     ;SWI "XWimp_GetWindowState"
  MOVVS R0,#-1     ;An error does return 0xFFFFFFFF
  MOV   R15,R14

Wimp_OpenWindow
  MOV   R1,R0
  SWI   &600C5     ;SWI "XWimp_OpenWindow"
  MOVVS R0,#-1     ;When we err we say &FFFFFFFF
  MOV   R15,R14

Wimp_CloseWindow
  MOV   R1,R0
  SWI   &600C6     ;SWI "XWimp_CloseWindow"
  MOVVS R0,#-1     ;Not working, then go one below zero.
  MOV   R15,R14

TemplateFontRef
   DCD -1
Wimp_LoadTemplate
  LDR   R4,TemplateFontRef
  MOV   R6,#0      ;Put in order the registers, as C calls of ACPS.
  MOV   R5,R3
  MOV   R3,R2
  MOV   R2,R1
  MOV   R1,R0
  SWI   &600DB     ;SWI "XWimp_LoadTemplate"
  MOVVC R0,R2      ;If all is right, give back the start of space unused.
  MOVVS R0,#0      ;When things fail, we go null, flat to zero.
  MOV   R15,R14

Wimp_OpenTemplate
  MOV   R1,R0
  SWI   &600D9     ;SWI "XWimp_OpenTemplate"
  MOVVS R0,#-1     ;As we fail, pass back one below, below none.
  MOV   R15,R14

Wimp_CloseTemplate
  SWI   &600DA     ;SWI "XWimp_CloseTemplate"
  MOVVS R0,#-1     ;On error, back goes, one less, less than none.
  MOV   R15,R14

  END
On RISC OS use the following commands to compile (with GCC and Asasm):

Code: Select all

asasm -o Wimp.o Wimp.s
gcc -mlibscl -Wall -std=c99 -o !RunImage main.c Wimp.o
And the criticism I get is, why did I use Assembly Language. There are plenty of other things that people could criticize about that code, though they ignore all the other stuff, and target my choice to use a little bit of assembly language.

FYI, this is a bit of code I produced in a single Morning in responce to a question on these forums. This is the kind of stuff I used to post often. I usually just do all this stuff from Assembly, so I had to write the C version from scratch not having any previous C code for the purpose.
Last edited by DavidS on Mon Jul 22, 2019 5:34 pm, edited 2 times in total.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

Musketeer
Posts: 152
Joined: Fri Feb 12, 2016 1:23 pm
Location: CZ

Re: I dont get it... Why is everyone from science schools so obsessed with Perl and Python when we got C?

Mon Jul 22, 2019 5:23 pm

Yieeehaaaw! :D :P :idea: New version of Free Pascal soon! There is some juicy stuff...

https://wiki.freepascal.org/User_Changes_3.2
https://wiki.freepascal.org/FPC_New_Features_3.2
Linux is like woman - both wants 180 % of your time...
You want speed Java 9.8x? Throw it out of some Window(s)!
My girlfriend is terribly unmature - she always sinks my boats in bathtub!

Return to “C/C++”