Advice on C / C++ programming

I am a newbie and just starting to learn. I am starting to learn C / C++ (and assembler as time permits) specifically to program / manipulate Atmel microcontrollers (ATMega328P, ATTiny13, etc).

Is the following statement true: My C / C++ code can be written in the Arduino IDE and compiled / uploaded to the Uno just as well as the Arduino language (assuming I don’t do anything in C / C++ the IDE can not handle).

Thank you in advance: if the answer is TRUE I will take what I learn in C / C++ and use in in the IDE.

In general it is true.

However the arduino has no concept of a console which is where the output of cout and printf() end up. you need to rewrite that code using serial.prints() to the PC.

Also, some data structures like linked lists don't work so well on arduino.

Thank you :slight_smile:

  1. The language used by the Arduino IS C/C++

  2. cout/cin sin's random numbers etc ........ are provided by lib's, you simply use the lib's which are appropriate to the target system. You can't use some lib's as the target system does not support them.

  3. linked lists etc are fine on the Arduino. But you must keep a very close eye on memory usage. This is true on any system, bit more so on the Arduino's as they have very little memory.

  4. Forget that assembler exists - it should NEVER be used for programming.

Mark

Mark:

Thanks for the advice.

I plan on learning assembler for the heck of it. I want to use the ATTiny13 once I figure how to to it all (I won’t be using the ATTiny13 with the Arduino IDE to kep life simple). I just want to learn assembler on a simple, small little chip. Who knows, maybe I will have a use for it.

(Also, some data structures like linked lists don't work so well on arduino.) =

(3. linked lists etc are fine on the Arduino. But you must keep a very close eye on memory usage. This is true on any system, bit more so on the Arduino's as they have very little memory.)

We said pretty much the same thing. The whole point of a linked list on most systems is that you don't have to worry about memory since the OS can stuff them almost anywhere. That is not a luxury the arduino can afford.

Given that each node in a doubly-linked list will suck up 4 precious bytes of memory - even before you get to the data - it seems to me that it would save a lot of memory to simply have an array of structs.

Languages such as C(well the ones that came before long before c) etc replaced asm because it is much simpler/quicker to use them than asm.

If you do write asm start by writing out the code you want in C and then hand compiling it.

Take a look at the Atmel IDE "Atmel studio" it supports C/C++ for all Atmel chips. (It's free) It also supports the Arduino .ino format.

Mark

Mark: thank you... will check it out now...

The whole point of a linked list on most systems is that you don’t have to worry about memory since the OS can stuff them almost anywhere

No. All systems limit the amount of memory an application can use. Normally to far less than the limit of virtual memory. There is no system on which you can just throw memory around.

Mark

I learned how a computer really works by writing assembly language. So it is good for educational purposes. But I would not go back to it now that I know C.

Going back and reading your assembly langauge after a couple of months you will see that it is hard to follow.

I think that it is actually important that people learn a little bit of assembly on a simple microcontroller or microprocessor.

It helps to understand the inners of a micro (accumulator, registers, maybe a peripheral or two). I learned this stuff on a 1802 punching in binary codes :wink:

I learned this stuff on a 1802

Ah, but it's not as much fun without a SEX instruction!

westfw:
Ah, but it's not as much fun without a SEX instruction!

Got C# for that, e.g.

catch(SqlException sex)
{
  ...
  ...