Writing simple stuff in C
Colin Ferris (399) 1818 posts |
As a matter of interest – how much of RO code is now written in ‘C’? |
Chris Mahoney (1684) 2165 posts |
In C# the guideline is that properties should be inlinable and that you should use a method for anything “slow”. In your example, FxCop can usually detect when you do it the wrong way, although there are plenty of developers out there that don’t bother to use it… |
Andy S (2979) 504 posts |
In C# the guideline is that properties should be inlinable […] Environment.Person could be used multiple times without penalty. It’s when I see people repeating the same chains of properties, like Environment.Person.StrideLength or longer, multiple times that it looks odd to me. Inlining dodges the overhead of method calls but surely the machine’s still got to follow the three pointers to locate the value in memory each time, unless the compiler’s smart enough to determine it won’t change between invocations. In C# maybe the JIT can optimise it out. I don’t know. I try not to use Microsoft’s products when I can help it these days. ;-) |
nemo (145) 2556 posts |
With regard to the shoddy compilation: The compiler could only claim to be dubious about the pointer’s constancy if there were some other pointer being written to (which could therefore overwrite the value). There isn’t, so there’s no excuse (I suppose it might believe that it could be pointing to itself. Uggh). The only other explanation is that it had been marked volatile. But as others have mentioned, the writeback is just nonsense.
My favourite programming language is PostScript. I would not recommend anyone learn it though. It has famously been described as a write-only language. It is certainly the only language where comments are absolutely required when writing as well as reading… and which are routinely removed before distributing. This is because it is stack based, and the state of the stack is of far more importance than the order of things in the source (thanks to However, PostScript can be maintained… but only by those who actually understand it. Assembler is the same. And here’s the pertinent point: There’s a lot more bad C in the world than bad assembler or bad PostScript. There’s a reason for that.
Meanwhile, elsewhere: “RISC OS is so great on PI because it’s so fast and it’s so small.” |
Sprow (202) 1158 posts |
Norcroft understands C99’s restrict keyword (page 103 onwards of Acorn C/C++ book). If you promise, on Scout’s honour, that the pointer can’t be aliased by another pointer somewhere else mehdef *restrict meh;you get ; generated by Norcroft RISC OS ARM C vsn 5.76 [19 Mar 2018] I suppose you could argue that since main() doesn’t call any functions that the compiler could infer that for you, but that’d be a pretty specialist assumption; most programs have functions spread across multiple files (which the compiler can’t see until it gets to them) so presumably plays safe and assumes the pointer meh might be aliased elsewhere, unless you state otherwise using restrict. |
Steve Drain (222) 1620 posts |
I bought a QUME CrystalPrint Postscript printer 1 with my A440 back in the days of Arthur, so no Draw. I bought the Blue and Red books 2 and learned enough PS to send files over a serial link to produce quite complex text effects. I had a little experience of Forth and RPN 3 from HP calculators, so it was not a complete shock. I agree that it is not to be recommended. I knew enough to work out that the printer’s interpreter did not deal with ‘Copies’ correctly and later to modify the RO driver with a different way to do it, but I have never returned to it since. 1 Horrendously expensive, but it lasted a dozen fault-free years and was the main school printer for a while. 2 I still have the manuals, which remain the exemplar for clarity. 3 Reverse Polish Notation |
Rick Murray (539) 13851 posts |
Ah, now that code is better. ;-) Odd that it sets R0 (exit value) before the final STR, and note there’s that final writeback. It’d be interesting to understand why the compiler does that. Maybe it’s an artéfact of the intermediate code? |
Jeffrey Lee (213) 6048 posts |
Which suggests that the strict aliasing related optimisations haven’t been implemented properly. int and *mehdef are two completely different types, so for most cases the compiler can assume that the programmer is obeying the rules of the language, i.e. two objects of that type won’t overlap in memory. https://www.approxion.com/?p=2656 ‘restrict’ is more for the case where you have multiple pointers to objects of the same type, so that you can tell the compiler that those objects don’t overlap. For objects of different types it shouldn’t be necessary. |
Willard Goosey (5119) 257 posts |
I’m not very familiar with ARM assembly yet, so stupid question time: What does the “!” at the end of the line mean? The stronghelp manual for assembly doesn’t seem to talk about it. |
Clive Semmens (2335) 3276 posts |
Writeback. The result of adding &14 to the value in a2 (to be used as the address) is written back to a2. This is pre-indexing – the next STR (probably – it’s possible to use this for other purposes, but that would be odd) will use this address with the next immediate value added. In post-indexing, the address in a2 is used, then the immediate is added to a2 ready for the next STR. The format for that is
Pre- and post-indexing works exactly the same way for LDRs. Without the !, a2 + &14 is used for the address, but a2 is left unaltered. |
Rick Murray (539) 13851 posts | |
Chris Mahoney (1684) 2165 posts |
Ah! Understood, and agreed :)
It might, but I’m too lazy to check. Meanwhile my day job is C# so I can’t really avoid it, although I don’t really have any problems with it either (although Visual Studio itself is another matter…) |
Glen Walker (2585) 469 posts |
Just remember…its better than peeling your eyeballs… |
Clive Semmens (2335) 3276 posts |
There. Fixed that for you. |
Willard Goosey (5119) 257 posts |
Thank you, that make sense. And I have to correct myself, the StrongHelp Assembly manual does talk about writeback, it’s just kind of hidden away. |
Andy S (2979) 504 posts |
Meanwhile my day job is C# so I can’t really avoid it, although I don’t really have any problems with it either Much as it can be fun to hate on M$, I have to agree. In terms of the language syntax as well as the speed of development (.NET has something for almost everything), it’s good. I certainly preferred those aspects to Java but that’s not saying much. Personally for my own stuff I’ve always chosen C or C++ though because I want something properly cross platform with less bloat. (although Visual Studio itself is another matter…) Er, yeah. I was comfortable with VS 2008. Each version after that seemed to me to go out of its way to just get in my way more, shuffle things around and slow me down. |
Glen Walker (2585) 469 posts |
Some of their software has been good, some of it has been appalling and the vast majority is simply uninspiring but what gets me irate is the sense of corruption, sneaky tactics to lock people in and generally anti-competitive behaviour which will only be to the detriment of everyone in the end. Also the smuggery and snobbish attitude of most Windows users is really really really annoying and totally unhelpful.
Last time I was a full-time C# developer I found it was incredibly easy and quick at generating code that was impossible to then debug but you did get an application out quickly which is of more concern to a lot of people. I couldn’t shake the feeling that it was symptomatic of a general malaise in the programming world and profession in general that there is a growing sense of disconnect between the code and the application. I guess its another step along the road with the first being a disconnect between assembly and C. I will be the first to admit that I don’t know enough assembly but I have a desire to learn, tinker and understand more of what is going on but I fear that a lot of people writing C# don’t even know what assembly code is and probably think “oh, that’s something embedded engineers need to know about, its not my problem”. Hmm…maybe it isn’t if the compiler is good… I don’t know, I guess I feel that people should care more about understanding things instead of just blindly using them. |
Rick Murray (539) 13851 posts |
I cannot watch “The Magicians” season two on Amazon Prime. Outside of France, perhaps. Here? Nope. Why? Well, I believe that NetFlix bought the territorial rights out from Amazon – which means if I want to watch this series I’ll be expected to subscribe to two different services… Okay, it’s not a big deal, but it does highlight that such practices and intentional lock-ins are quite common…
?!? I can understand snobby Apple users, but Windows? How can anybody who isn’t a total fanboi defend all the unsavoury stuff around Windows 10? The upgrades that take no to mean yes, the fact that the “WE WANT YOU TO UPGRADE” was more pervasive than viruses, and all the snooping? Having said this – you’ll find way back when that us Beeb owners pointed and laughed in the general direction of anybody who had a Spectrum. And, okay, let’s face it, the Spectrum was pretty rubbish. But despite that, one can think that the rivalries got coders to do some incredible things. Overcoming limitations and squeezing the most out of the hardware gave birth to a generation of programmer the likes of which the world will never see again.
That’s what VisualBasic was intended to do. Point and click programming…
Where do you draw the line? C → assembler → CPU implementation → transistor logic → electron behaviour in silicon…? |
Glen Walker (2585) 469 posts |
There is no line! Only available time… |
Steffen Huber (91) 1953 posts |
If you think C# (or Java) is impossible to debug, what do you think is a language or environment that is easy to debug? |
nemo (145) 2556 posts |
Well if you hate Visual Studio to the point that you don’t use it, that would make debugging difficult. I like Visual Studio (even if Intellisense went a bit strange after VS6). As RISC OS has never had anything with even a fraction of its functionality, complaining about it here is like criticising the colour of the neighbour’s jetpack to justify why one is forced to walk. |
Clive Semmens (2335) 3276 posts |
It’s the way he burns down the garden fence every time he goes to work that I criticize his jetpack for… |
Steve Pampling (1551) 8172 posts |
Excel – bought from another company
Early Access, then they bought FoxPro and hacked around a bit to produce an “uninspiring”
Google, Apple, < insert more large corporation names > all having a double does of the arrogance gene
Point and click code joining is probably closer to the mark |
Rick Murray (539) 13851 posts |
Yes. DDT is very ‘80s, isn’t it?
FoxPro. I used to be pretty good at the DOS version. Used it a lot in estate agency, so I made lots of useful forms and reports. There was an art in getting the best layout on a 80×24 ANSI screen…
What amazes me, specifically about Google, is the number of things they do and the number of products they have, and can you actually raise a concern with a company employee? Can you hell. Oh, and applying the nebulous “rules” of YouTube differently depending on whether one is making lots of money through advertising, or not. This is probably why PhewDeadPie (or whatever his name was) had to literally create a PR disaster before they took notice. I bet a little unimportant nobody like me would just need to make one single anti-semetic comment in passing (hmm, like WTF is there no “Palestine” on your mapping service?!?) to receive a similar reaction… But the biggest worst hypocrite of them all must surely be James Wales. What he created is impressive, certainly. But the whole editing failure (ego before knowledge), dubious use and abuse of copyright, the constant begging for money (would you really donate the $15 dollars urgency needed to keep the site online if, at the same time, they pointed out that the foundation has around $90M in assets and the hosting expenditure only takes around 6% of the yearly revenue?). But, then, it gets better. The whole idea of “blacking out” what ought to be a non-partisan service for political ends…
;-) The VisuslBasic that I used predated StackOverflow. |
Steve Pampling (1551) 8172 posts |
I did say in the bad side Access – because the faster database engine that appeared in that came from FoxPro. Rather like putting a Mercedes F1 engine in a rusty Trabant – it’ll go faster for while and then fall apart horribly. |