Arduino / compilers on uC

I used a 'bool' (then a 'boolean') to represent a boolean quantity. Isn't that the point of having a boolean type?

If the compiler's code absolutely depends on a variable having certain values and no others, the compiler should take steps to ensure that the variable contains a legal value. Instead, it prevented me initializing the variable to a known condition.

That's a common circumstance--variables aren't initialized to known conditions when power's applied.

What's the value in having a 'boolean' if you have to ultimately use bizarre, unsigned, faked, phony types to ultimately represent it with a byte anyhow?

No, the compiler *is* at fault. It optimized out the operation

w = (U.dat.flg ? true : false;)

substituting: U.dat.flg ==> w.

1 2 3 w = (U.dat.flg) ? (true) : (false);

To do that is to assume expression #1 (U.dat.flg != 0) is equivalent to, has the same range of values as, and is interchangeable with expressions of type 'boolean' #2 & #3.

That's wrong.

Cheers, James Arthur

Reply to
dagmargoodboat
Loading thread data ...

It's not an actual Arduino. I designed an ATmega-based controller, but made it Arduino-compatible. The hardware is much tougher than an Arduino, but yes, I'm programming it over USB using the Arduino IDE.

Cheers, James Arthur

Reply to
dagmargoodboat

it is a balancing act between portable code and portable language while keeping up performance

Reply to
Lasse Langwadt Christensen

I disagree profoundly. There are different definitions of constness, all useful in different situations, but the compiler enforces only one: bitwise constness.

That means that if I have some object that has invisible internal state, such as a reference-counted string, it can never be const unless I can cast away constness (or use _mutable_ in c++, once that came along).

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

Does the Arduino IDE support gdb yet? The reason I dropped it long ago was that the burn-and-crash development model was so 1980.

I had full source-level debug in Microsoft C 5.0 in about 1988.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

When I interviewed at HP Labs many years ago, they asked me to derive the Fresnel formulae for reflection of a plane wave at a dielectric interface. I said, "Well, I won't crank through all the math, but here's how the derivation goes...." and talked about how phase matching in the plane restricted the directions of the outgoing waves, and then how continuity of tangential E and perpendicular D gave a 2x2 matrix equation for the relative amplitudes in both polarization cases. The interviewers seemed very happy. (Probably they'd had to watch various others go through the math, which would have been about as interesting as watching paint dry, especially on the Nth repeat.)

That's about the only question of that sort I've ever been asked in an interview.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

I agree. This generated code should/could be more defensive. But it's not incorrect, as David has been patiently explaining.

That's true, but not in C. The startup code (before main) is expected to initialize all global and static variables to zero, and the compiler is entitled to expect that. (Startup code is not part of the compiler).

If you use a union over multiple types, you are entirely responsible for your program's type safety.

Clifford Heath

Reply to
Clifford Heath

YES. So much this. The right way to build capability is help the user to take small steps on solid ground, not to give them jet powered boots to leap between mountain tops.

Reply to
Clifford Heath

Makes me want to use one of the two dozen "Me too!" complied non-VM languages that have as their mission statement something like "We're endeavoring to create a language with the speed of C/C++ and the ease of use, flexibility, and unambiguous syntax of an interpreted language."

Reply to
bitrex

Maybe not two dozen, we got C#, Objective-C, D, Delphi, Crystal, Go, Rust, Swift, Haskell, Scala...

Reply to
bitrex

C# uses the DotNET VM. Scala is just Java in a gorilla suit.

There are lots of obscure languages though, I'm sure "two dozen" is well below the mark. Also... quite a few languages have an LLVM front end, which allows them to be fully compiled.

Reply to
Clifford Heath

Quite possibly they have resolved it one way or the other since I was keeping an eye on it.

My conclusion remains that the language has become so complex that it becomes part of the problem rather than part of the solution. Listening to sage people that have not been at the sharp end of diagnosing problems but also part of Working Groups does nothing to dispel the conclusion.

Languages should be easily understandable by humans, if humans are to stand a chance of writing reasonably correct programs.

Libraries are different, of course, since arbitrary people create them and that can't be controlled. But at least a solid language definition should enable good tool support.

For all its disadvantages, Java is streets ahead in those respects. Comprehensive "control-space" completion and comprehensive refactoring browsers are a significant advance.

Reply to
Tom Gardner

That's a valid point.

I keep looking, but nothing has made me jump, yet.

I suspect my next foray into code will be on the XMOS devices, since the compiler guarantees timings and the language and processors are based around CSP-style comms mechanisms. (Not surprising, since one of the founders was heavily involved in OCCAM/transputers.

Reply to
Tom Gardner

That's a lovely kind of answer, since it demonstrates you know how the maths is supporting and clarifying the physics and objectives.

Reply to
Tom Gardner

Yes, Finally, someone knows what's going on ;) Actually, that holds TRUE in most languages I deal with ..

Jamie

Reply to
M Philbrook

I am glad you dont do any coding work for me or anyone I deal with..

Reply to
M Philbrook

fc

01 movw r30,

fd

4f sbci

fc

01
55 1014: fd 4f

lpm r18, Z 1018: fc 01

0x4B ; 75 101c: fd 4f

lpm r30, Z 1020: ee

; 0x1026

breq .+78 ;

91 f0 breq .+36

a9 f0 breq .+42

01 f5 brne .+64
8f 7d andi r24,
0x1062
91 f0 breq .+36

a1 f0 breq .+40

b9 f4 brne .+46

03 c0 rjmp .+6
80 93 80 00 sts

8f 77 andi r24,
36 1064: 09 c0
03 c0 rjmp .+6
80 93 b0 00 sts

ee

0f add r30, r30

subi r30, 0x55 ;

a5

91 lpm

in r24, 0x3f ; 63

r30, X 108c: 61 11

0x1096

and r18, r30 1094: 01

st X, r18 109a: 8f

ret

This is like saying that wheelbarrows are better than trucks because one specific model and brand of Semi has undergone a recall.

If you're using a _decent_ optimizing compiler, then you should be able to just state your intent reasonably clearly, then stand back and let the optimizer do its business.

If you're using a _broken_ compiler with _crappy_ libraries, then you should first try to fix that situation. If you simply cannot then yes, you would need to do things the old fashioned way.

--
Tim Wescott 
Control systems, embedded software and circuit design 
I'm looking for work!  See my website if you're interested 
http://www.wescottdesign.com
Reply to
Tim Wescott

I don't know if gdb is supported. At bottom the Arduino IDE is just a pre-processor to gcc (written in Java!), so I don't see that the tool chain would preclude it. But it all runs in FLASH, which might make break-pointing a bit of a bear.

Ages ago, the 300-odd line debugger I wrote single-stepped the 8051 through EPROM by setting an interrupt before passing control to the user program. That causes the 8051 to execute the next instruction, before it handles the interrupt. The debugger, thus, could step execution one step, then regain control.

That's pretty useless for debugging code running in real time though-- ISTM you'd need an emulator at that point.

Yep, me too.

Cheers, James Arthur

Reply to
dagmargoodboat

[...]

It's ultimately gcc, a well-regarded compiler. The difficulty I have with the whole thing is this paradigm of abstraction, blindly applied to isolate workers from their task.

In this case I've shown the Arduino IDE and gcc both, in separate examples, impeded rather than aided.

Cheers, James Arthur

Reply to
dagmargoodboat

ago

You can do it in AVR Studio.

Cheers

Phil Hobbs

Reply to
pcdhobbs

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.