which object orient language is most suitable for embedded programming?

Yes, I know that C enums are more flexible than Pascal enums in this way. I should have been clearer and asked for a way to get the highest value in an enum, rather than the number of elements. Then you could have something like:

typedef enum { red, green, blue } colours; unsigned long int colourValues[highestof(colours) + 1];

although the syntax

unsigned long int colourValues[colours];

would be far better, especially if there were any typechecking. Similarly, highestof() could be used when looping through all elements of an enum, or for run-time range-checking of enum values.

When using enums with holes, or non-zero first elements, then the validity of highestof() depends on the code - compiler warnings could be useful here.

Of course, this can all be done at the moment by defining "colours" as:

typedef enum { red, green, blue, noOfColours } colours;

but it would be more elegant to be able to have such compile-time type information in a consistent manner.

Reply to
David Brown
Loading thread data ...

Heh - you've pretty much explained exactly *why* I prefer access methods ;).

One other point is that the simple process of deciding what's local and what's public tends to lead to more appropriate data structures anyway. And deciding which module is responsible for what might otherwise have been global data is a process I tend to find illuminating. There are very cases, IME, where a strong case can be made for truly global data - and even in those cases, there tends to be a natural owner. Similarly grouping the functions that are most closely associated with the data within the same module again tends to promote "good" code. In other words, there are advantages not just in the practice, but in the discipline it brings.

Yes indeed - the header for the module which contains the class. This module owns the class. Why should any other module need to know anything about it other than its use?

Yes, I've thought about doing exactly that. Years ago I worked for a guy who used Jackson (JPL) diagrams, and a programming framework that worked in Jackson. He'd use the tool to break the design down structurally and graphically, and then fill in the boxes with code (whether in Basic or assembler etc). It worked well, in separating the design from the coding, but still allowing the code to written by hand. I sorta visualised a similar kind of thing....

Eeek! Heresy! ;)

Steve

formatting link

Reply to
Steve at fivetrees

On some processors, loads may extend (sign or unsigned or both) for free, but often other instructions are only available in native register widths - sooner or later, masking is needed. And on some 32-bit processors, loading a 16-bit value is smaller and faster than loading a

32-bit value (perhaps you have a 16-bit external data bus). In other words, the fastest type may even vary between implementations of the same cpu core.

Again, this shows what variance there is. Getting optimal values or types is unlikely to be practical for all cases - using minimum sizes for static data and optimising local register usage is probably the best balance.

Reply to
David Brown

This is what I do. (I make it "Colours", though, to denote it as an honorary type ;).)

And to agree with another part of this thread, I'd also like "colours" to be a proper type, and only allow values from the enum (which I capitalise, to denote them as constants - but hey ;)).

Steve

formatting link

Reply to
Steve at fivetrees

Erm. Should be "There are very *few* cases..." etc.

Steve

formatting link

Reply to
Steve at fivetrees

Why would you want a sign extend with enums ? A zero extend would be more appropriate in most cases.

The zero extension on x86 would be something similar to

XOR AX MOV AL,enumval

This was the idea behind using uint_fast8_t :-).

Paul

Reply to
Paul Keinanen

Well, it doesn't, and isn't. Modula-2 and Ada have all of the same low-level stuff that C has. Modula-3 has most of it, but trades static allocation for garbage collection (from dim memory). Ada has static stuff

*and* objects. All three were explicitly designed to be systems languages.

Cheers,

--
Andrew
Reply to
Andrew Reilly

I like what the Visual Basic variants have, which is along the lines of (I'm rusty here...)

FOR Each Varname IN Typename DO Array[Varname] = etc

this is both typesafe, edit safe, and very clear what is actually happening.

-jg

Reply to
Jim Granville

Do they support pointers like C? For really low-level programming (eg. implementating strcmp in C) things like pointer casts and pre/post increments are quite useful.

Wilco

Reply to
Wilco Dijkstra

Modula-2 and Modula-GM have POINTER and ADDRESS types. Anything you could want to do at a low level was available to you. M-GM is the language used by GM/Delco/Delphi to program the engine/transmission controllers in millions of cars and trucks per year beginning in the mid 90's. The controllers used a very small amount of assembly where a HLL couldn't be used (e.g., register initialization at powerup).

~Dave~

Reply to
Dave
[Snipped]

What about D ?

formatting link

Regards Anton Erasmus

Reply to
Anton Erasmus

Maybe D-- would suit me.... or maybe Solder++

martin

Reply to
martin griffith

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.