Go Down

Topic: Is Arduino ANSI compatible ? (Read 659 times) previous topic - next topic

hary

Hello.

Well, that's my question.

One of the reason I choosed Arduino is that it was programmed in Arduino wich was supposed cloth to C.

But Now I have a doubt whether an Arduino code can easily be put on another uC.

I've read somewhere that the C compiler has to be ANSI compatible to make the move on different uC easy. And it seams that not all C compiler are .

KeithRB

It is a mixed bag. Since the Arduino has no concept of a file system, most of stdio is right out. It is also heavily C++ based, not C based.

Generally when you talk about porting it is to a processor of at least similar abilities. It should be pretty easy to port Arduino code to a PIC, lets say, but makes little sense on a Cray.

lloyddean

The compiler is a C++ compiler that much is so.  But as to being ANSI compatible?  No as to be ANSI compatible it must include the full suite of C/C++ libraries and STL which it does not.

Then again given the limited resources the hardware platform the compiler supports is not fully capable of supporting these libraries either.

Then there are the memory allocation, deallocation and access decorators which make code developed for the hardware non portable to others platforms without due consideration.

MichaelMeissner

#3
Apr 08, 2013, 11:31 pm Last Edit: Apr 08, 2013, 11:33 pm by MichaelMeissner Reason: 1
First of all, as of 1990, the ANSI C standard became the iSO C standard  with modifications (ANSI is one of the US standards bodies, ISO is world wide standards).

The language the IDE supports is C++, not C.  While C++ is mostly upwards compatible with C, there are differences in the corner cases.

At the standardization level C has two levels, hosted and freestanding.  I believe C++ is the same way.  Arduino comes in as a freestanding implementation, but the library does implement some of the libraries from the hosted standard (things like memcpy, malloc/new, etc.).

C++ and C both came out with new versions of the standards recently.  For the C language, this is the C11 standard (C99/C90 being the previous two ISO versions, C89 being the ANSI standard before the ISO certification process).  For the C++ lanuage, this is the C++11 standard (C++98 was the previous ISO standard).

Finally, the Arduino team has decided to stay on a rather old version of GCC (4.3.2 that was released on August 27, 2008).  GCC 4.8.0 was just released on March 22nd, 2013.   So the C++ that is currently supported in the Arduino IDE is based on the C++98 standard.

And yes, I have been a language lawyer in the past, and I was on the original ANSI X3J11 C standards committee many years ago.

mrburnette


PeterH


Since the Arduino has no concept of a file system ...


It isn't integrated into the standard 'C' runtime library, but there is an SD library which can be used to access a filing system on SD cards.
I only provide help via the forum - please do not contact me for private consultancy.

KeithRB

Quote
It isn't integrated into the standard 'C' runtime library, but there is an SD library which can be used to access a filing system on SD cards.


So it isn't ISO compliant, which is kind of the point here.

MichaelMeissner


Quote
It isn't integrated into the standard 'C' runtime library, but there is an SD library which can be used to access a filing system on SD cards.


So it isn't ISO compliant, which is kind of the point here.

As I said, the ISO standard has two levels, hosted and freestanding.  Freestanding is without libraries, other than what is needed to implement missing instructions (floating point and long long emulation for instance), and the stdarg.h library.  So, it could meet a freestanding ISO specification, if you used an appropriate compiler, and could add the options to more strictly conform to the ISO standard.

Go Up