C
Cursitor Doom
Guest
On Sun, 02 Jun 2019 09:39:37 +0000, Jan Panteltje wrote:
> seeplusplush is a crime against humanity.
+1
> seeplusplush is a crime against humanity.
+1
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
On a sunny day (Sun, 2 Jun 2019 17:55:07 +1000) it happened Clifford Heath
no.spam@please.net> wrote in <xhLIE.27461$NT5.464@fx47.iad>:
On 2/6/19 8:06 am, John Miles, KE5FX wrote:
On Saturday, June 1, 2019 at 3:06:15 AM UTC-7, Cursitor Doom wrote:
On Fri, 31 May 2019 17:02:54 -0700, John Miles, KE5FX wrote:
The advice to start with K&R C is OK as far as it goes,
but it's akin to telling an electronics novice to start with
vacuum tubes.
What's wrong with that?
For one thing, you'll be outcompeted by people who spent the same amount
of time learning modern techniques.
For another, people who advocate K&R C are looking through rose-colored
glasses to some extent. There is some genuinely crappy code in that
book, and some of the decisions made in the early history of C and
its standard library have probably cost us hundreds of billions of dollars.
The most costly mistake in the history of programming has to be "errno",
from Unix. DOS and Windows copied it, more or less.
Recall "Unknown error 0x80000000"? We Unix folk used to laugh, but it's
just what you get when a call returns -1 or NULL without setting errno.
Probably the programmer screwed up in that case.
Read the documentation for that function if it is in libc.
Lemme state that if you really do not know what is happeing you should not be programming.
What I usually do in C is have a printf() at the start of each function, that can be activated by running the thing
with a command line flag:
if(verbose)
{
fprintf(stderr, "my_function_do_something(): returning *result=%d\n", *result);
}
....
If you put the error report in every function that way,
then you see any problems in verbose mode in a few seconds.
libc.info is good.
I you have never heard of it (it should be on your Linux system)
On Sunday, June 2, 2019 at 12:42:43 AM UTC-7, Clifford Heath wrote:
Tend to agree, but what can you expect for nothing? OTOH it can be done
well. How do you find this C++ and documentation:
https://github.com/cjheath/AD9959>?
That's an amusing coincidence. I spent this afternoon duct-taping
an AD9959 demo board to a Mega2560 for a one-off production test rig,
when I wasn't on here arguing with (seemingly drunk) people about C.
The board refused to put out a signal at first, and having seen your page
in the Google results for 'AD9959', I was tempted to crib your register
settings from it. It eventually occurred to me to run the ADI software
and dump its registers for comparison, but your source code was going to
be the next resort if that hadn't worked.
Looks good to me, for what that's worth.
Jan, I've read your code. I've worked in C for 40 years, with many
dozens of good C programmers, and though I think you're a terribly
clever guy, having seen your code, I would never recommend my boss to
hire you. Your code is worse than your pencil-drawn schematics, and
that's really saying something.
Probably the programmer screwed up in that case.
Yes. But they followed the paradigm that you can only return one integer
as an error indication. That's the problem. Functions need a way to
efficiently return more error information. Programmers should not follow
that pattern. But fprintf(stderr...) is unacceptable as well (see below).
Read the documentation for that function if it is in libc.
Lemme state that if you really do not know what is happeing you should not be programming.
int fd = open("/a/b/c/d", 0)
if (fd < 0)
{
// Even after looking at errno, I have no fucking idea what went wrong.
}
What part of the above is difficult for you to understand?
What I usually do in C is have a printf() at the start of each function, that can be activated by running the thing
with a command line flag:
Jan, I've read your code. I've worked in C for 40 years, with many
dozens of good C programmers, and though I think you're a terribly
clever guy,
having seen your code, I would never recommend my boss to
hire you.
that's really saying something. You get stuff done, but pity the poor
bloke who comes after.
if(verbose)
{
fprintf(stderr, "my_function_do_something(): returning *result=%d\n", *result);
}
...
If you put the error report in every function that way,
then you see any problems in verbose mode in a few seconds.
You can't build library code that way. It may be ok for command-line
prototypes and open source trash, but no software product can do that.
libc.info is good.
I you have never heard of it (it should be on your Linux system)
I have worked with Unix since the 1970s. I have no need of such trinkets.
Oh yes it can, and you will be ever so happy if a user has a problem
with your code you can have them execute it from a terminal and send you
the text.
On 6/1/19 8:13 PM, Tom Gardner wrote:
There's not that much trouble you can get into on an ATmega, but it's
very educational to single-step your code at the assembly level.
Plus <stdio.h> isn't that small, so printf() isn't a huge help, and
there's no semihosting.
Just so, on all counts.
It can be very entertaining looking at heavily optimised
C code, and single stepping it for that matter. Obfuscated
is the word that springs to mind.
there are plug-ins for other IDEs you can develop Arduino code with that
will show you the optimized asm your C/C++ code generates for AVR, ARM,
MSP430, MIPS, etc on the fly, in real-time as you type
There's not that much trouble you can get into on an ATmega, but it's
very educational to single-step your code at the assembly level. Plus
stdio.h> isn't that small, so printf() isn't a huge help, and there's
no semihosting.
Just so, on all counts.
It can be very entertaining looking at heavily optimised
C code, and single stepping it for that matter. Obfuscated
is the word that springs to mind.
libc.info is good.
fI you have never heard of it (it should be on your Linux system)
I have worked with Unix since the 1970s. I have no need of such trinkets.
That is a very very stupid remark.
On 6/1/19 8:13 PM, Tom Gardner wrote:
There's not that much trouble you can get into on an ATmega, but it's
very educational to single-step your code at the assembly level.
Plus <stdio.h> isn't that small, so printf() isn't a huge help, and
there's no semihosting.
Just so, on all counts.
It can be very entertaining looking at heavily optimised
C code, and single stepping it for that matter. Obfuscated
is the word that springs to mind.
there are plug-ins for other IDEs you can develop Arduino code with that
will show you the optimized asm your C/C++ code generates for AVR, ARM,
MSP430, MIPS, etc on the fly, in real-time as you type
On 3/6/19 1:05 am, Jan Panteltje wrote:
libc.info is good.
fI you have never heard of it (it should be on your Linux system)
I have worked with Unix since the 1970s. I have no need of such trinkets.
That is a very very stupid remark.
I don't like GNU "info" is all. Or anything that forces me to remember
my rusty EMACs keystrokes. I just use the man pages. "man 2 open" works
pretty well.
On a sunny day (Sun, 2 Jun 2019 22:57:19 +1000) it happened Clifford Heath
no.spam@please.net> wrote in <RIPIE.36172$xY3.34375@fx01.iad>:
int fd = open("/a/b/c/d", 0)
if (fd < 0)
{
// Even after looking at errno, I have no fucking idea what went wrong.
}
What went wrong is that 'open' failed
... > // if you think he user is a moron, then you can do a test for the
directory chain.
On 3/6/19 10:09 am, bitrex wrote:
On 6/1/19 8:13 PM, Tom Gardner wrote:
There's not that much trouble you can get into on an ATmega, but
it's very educational to single-step your code at the assembly
level. Plus <stdio.h> isn't that small, so printf() isn't a huge
help, and there's no semihosting.
Just so, on all counts.
It can be very entertaining looking at heavily optimised
C code, and single stepping it for that matter. Obfuscated
is the word that springs to mind.
there are plug-ins for other IDEs you can develop Arduino code with
that will show you the optimized asm your C/C++ code generates for
AVR, ARM, MSP430, MIPS, etc on the fly, in real-time as you type
I've just hand-built a Makefile for a client's SAMD Arduino project that
allows it to be compiled inside an Atmel Studio project so we can debug
USB re-enumeration issues. Contrary to what it says on the tin, Atmel
Studio cannot create such a Makefile for an Arduino project
automatically - it doesn't even get close, I tried.
I have no idea why the original author thought it was reasonable to
attempt to develop a 10KLOC commercial product using Arduino. Least of
all a SAMD product - the BOSSA code loader is the biggest load of shite
I've come across in years, and the author doesn't seem to even care, so
I'll name-and-shame him:
https://github.com/shumatech/BOSSA/pull/98
Clifford Heath.
On 6/2/19 9:10 PM, Clifford Heath wrote:
I've just hand-built a Makefile for a client's SAMD Arduino project
Large projects I write, prototype and debug all the algorithms and
classes and components, in portable C++, as if I'm writing an
application for a desktop x86 machine.
avr-gcc and arm-gcc tend to generate very compact code, even from
template-heavy C++11.
Obviously keeping in mind the resource limitations of the processor it
will end up running on.
Please, save your programming advice for someone who needs it The OPC++ doesn't support...
It's good programming practice to...
in C++ it's very straightforward to...
On 5/31/19 6:48 AM, Terry Pinnell wrote:
I bought my first Arduino UNO R3 kit two weeks ago (the Elegoo Super
Starter kit)
and am stepping through its tutorials. In parallel I'm trying to learn
the basics of
its C++ based programming language, but that's proving a struggle. I'm
impatient to
use Arduino on my own projects so I will take a 'copy/paste/edit'
approach. It then
becomes a matter of finding sketches that cover a particular subject
and then
tailoring.
I'd therefore appreciate recommendations on Arduino sketch sources
that others have
found useful please.
Terry, East Grinstead, UK
An advantage of C++ is you can write code to define rule-enforcing data
structures like that to, by design, self-enforce safer further design
decisions. Along the same lines raw data types like "int" should never
be used and passed around to represent something like dollars in a bank
account, or velocity. They should be wrapped in an object that enforces
assumptions like class Dollars, or class Velocity. A function that
computes an output velocity from an input velocity should return a
Velocity and take a Velocity argument e.g. Velocity
calc_new_velocity(Velocity v) not int calc_new_velocity(int v).
And no, this almost never "bloats the code" if done intelligently the
compiler and optimizer will figure out that in almost all cases it can
compute a velocity under the hood by just manipulating the raw ints like
it would when compiling C. all the boilerplate is mostly for your
benefit so it can warn you if you try to do something stupid.
On 3/6/19 12:26 pm, bitrex wrote:
On 6/2/19 9:10 PM, Clifford Heath wrote:
I've just hand-built a Makefile for a client's SAMD Arduino project
Large projects I write, prototype and debug all the algorithms and
classes and components, in portable C++, as if I'm writing an
application for a desktop x86 machine.
So would I, but that would cover less than a third of the code in this
case, since it's all about hardware access (I2S links to feed audio to a
3G modem, etc) and that's where the bugs are. It probably should have
better device driver testing, but it is what it is, not by my choice.
...if I'm unsure of what kind of code will be generated.
Absolutely no need for that in this case.
avr-gcc and arm-gcc tend to generate very compact code, even from
template-heavy C++11.
Yes, exactly.
Obviously keeping in mind the resource limitations of the processor it
will end up running on.
Plenty of grunt here. This processor was chosen for its peripherals.
C++ doesn't support...
It's good programming practice to...
in C++ it's very straightforward to...
Please, save your programming advice for someone who needs it The OP
is trying to climb the hill of his first embedded C. More advanced
lessons can come later, but I wanted him to know that Arduino has
definite downsides! Atmel Studio is a much better option.
Clifford Heath.
I bought my first Arduino UNO R3 kit two weeks ago (the Elegoo Super Starter kit)
and am stepping through its tutorials. In parallel I'm trying to learn the basics of
its C++ based programming language, but that's proving a struggle. I'm impatient to
use Arduino on my own projects so I will take a 'copy/paste/edit' approach. It then
becomes a matter of finding sketches that cover a particular subject and then
tailoring.
I'd therefore appreciate recommendations on Arduino sketch sources that others have
found useful please.
Terry, East Grinstead, UK
On 6/1/19 7:38 AM, Lasse Langwadt Christensen wrote:
lørdag den 1. juni 2019 kl. 12.45.13 UTC+2 skrev Terry Pinnell:
Terry Pinnell <me@somewhere.invalid> wrote:
I bought my first Arduino UNO R3 kit two weeks ago (the Elegoo Super
Starter kit)
and am stepping through its tutorials. In parallel I'm trying to
learn the basics of
its C++ based programming language, but that's proving a struggle.
I'm impatient to
use Arduino on my own projects so I will take a 'copy/paste/edit'
approach. It then
becomes a matter of finding sketches that cover a particular subject
and then
tailoring.
I'd therefore appreciate recommendations on Arduino sketch sources
that others have
found useful please.
Terry, East Grinstead, UK
Thanks to those who suggested useful sources of code, a couple of
which I've added
to my already extensive 'Arduino Code' bookmarks.
As per my opening post, I am already stepping through the Elegoo
tutorials, some 37
projects. And dipping in and out of two other sets.
As also explained, I don't want to master either C or C++. I want to
reach the stage
I described: minimal competence for a copy/paste/edit approach.
https://en.wikipedia.org/wiki/Cargo_cult_programming
The number of circuits that are cobbled together from app notes is
large, but dwarfed by the number of Frankenprograms made by cut-n-paste
from Stack Overflow.
Cheers
Phil Hobbs
On 6/1/19 10:43 AM, Dennis wrote:
On 6/1/19 6:06 AM, Clifford Heath wrote:
On 1/6/19 4:50 pm, Tom Gardner wrote:
What you gain on the swings you lose on the roundabouts.
While I am certainly no fan of C++ (e.g. see the C++ FQA),
one advantage of the Arduino class machines is that you are
programming against bare silicon.
If you think that 120 CPU cycles to set or clear a port pin is "bare
silicon" then I don't know what to think. That's how long
"digitalWrite" takes to perform a 2-cycle operation.
That is because digitalWrite() allows you to dynamically assign the
pin at run time. If you have a fixed pin you want to use and speed is
important, you can use builtin assembler operations (DDRx,PORTx,PINx)
to get your two cycle operation. Most beginner projects are more human
speed so 2 or 200 cycles doesn't make much difference.
The Arduino C libraries are a really bad direction to start off in,
even for a raw beginner. They are so unnecessarily so very badly
implemented.
Yes some of them are awful, but the more common ones are good and
getting better. For the beginner it lets them easily get something
working even if the dark corners have dragons.
Besides it can be a learning experience going through the library code
to see what is screwed up (not for the beginner or faint of heart!).
Not a bad method.
I taught myself circuit design largely by reading app notes, assuming
that all the circuits were junk, and figuring out why. (Some of them
are okay, of course, but you can always think about input protection and
so forth.)
Cheers
Phil Hobbs
"Arduino" is just an API. The Arduino-provided IDE sux balls. But you
can use the processor-specific API with an IDE of your choice though,
with a little work, just so you can use e.g. digitalWrite, analogRead,
Serial.begin etc. and not have to muck with setting up all the registers
and interrupts yourself. For many (even "professional") projects they're
fine. So maybe digitalWrite sometimes takes 100 clock cycles. BFD. Fix
it if/when you know you need to flip the pins faster.