Hi all =]
I'm trying to find a way to create complex arrays of types of variables and i wonder if it's possible in Arduino language to create a type of a variable,like in C?
for example: a type of variable called Point which holds two numbers of type Integer,then creating an array of it:
point grid[4][4]=
{
{0,0}{0,1},{0,2},{0,3},
{1,0}{1,1},{1,2},{1,3},
{2,0}{2,1},{2,2},{2,3},
{3,0}{3,1},{3,2},{3,3}
};
When a function calls it,it actually gets two numbers instead of one.
I know there are probably other ways to do this (2 sets arrays,an array twice the size with 'special instructions' how to pull the info out,...) but i wanted to know if it possible,regardless of the purpose it might serve.
Thank you for the help!
There is various typos in your code but what you're trying to do is basically valid and can be implemented without any problem in C++. For all practical purposes the Arduino language is C++.
English IS Australian...
(Arduino users all only code in C++....)
As soon as it's adapted, modified, it's no longer strictly speaking that language... it's a dialect or a mutated version, unless it's a C++ compiler that is, if you do
something that's no longer allowed in a traditional C++ compiler (eg, digitalWrite or infact any of the libraries that Arduino's IDE uses... it's no longer a C++ compiler)
it's a C++ hybrid or extension...
in the same way Delphi is an Object Pascal compiler, and certain directives, certain code is no longer compilable.
So Arduino really is Arduino, which happens to compile C++ code?
cjdelphi:
As soon as it's adapted, modified, it's no longer strictly speaking that language... it's a dialect or a mutated version, unless it's a C++ compiler that is, if you do
something that's no longer allowed in a traditional C++ compiler (eg, digitalWrite or infact any of the libraries that Arduino's IDE uses... it's no longer a C++ compiler)
it's a C++ hybrid or extension...
Not really. C++ (or C) allows you to define your own functions. A user-defined function is all that digitalWrite is.
kimkash:
I'm trying to find a way to create complex arrays of types of variables and i wonder if it's possible in Arduino language to create a type of a variable,like in C?
The answer is "yes" because it is "like C". In fact it is identical to C++. If you really want to have "exactly C" then add a .c file to your project. But I doubt the OP is really worried about exactly using C (compared to C++).
About the only difference are hardware-related extensions (eg. the ISR declarations) which are aimed squarely at interfacing with the hardware.
But if you can declare something (like "complex arrays of types of variables") in C++ you can declare it in "the Arduino language".
English IS Australian...
(Arduino users all only code in C++....)
As soon as it's adapted, modified, it's no longer strictly speaking that language... it's a dialect or a mutated version, unless it's a C++ compiler that is, if you do
something that's no longer allowed in a traditional C++ compiler (eg, digitalWrite or infact any of the libraries that Arduino's IDE uses... it's no longer a C++ compiler)
it's a C++ hybrid or extension...
in the same way Delphi is an Object Pascal compiler, and certain directives, certain code is no longer compilable.
So Arduino really is Arduino, which happens to compile C++ code?
[/quote]
Actually, the specifically Arduino bits are converted by a preprocessor, and/or just links to uncompiled libraries all in c/c++ and then fed into cpp and gcc (specifically an avr chip family aware version of cpp and gcc).
Thus, Arduino is C++ with some automatically linked helper libraries and header files that add the Arduino flavor at the source code level.
As a person who has never programmed in their life, if they use nothing else except Arduino's IDE and an Arduino Board, can they claim
to be a C++ programmer?
I don't think your question admits to a yes or no answer.
However if you say "a person who has never programmed in their life" then clearly they are not a programmer of any sort.
If you use some of the more complex examples around, then I suppose the distinction would be if they have copied and pasted without understanding, or if they used the code, analyzed it, understood it, etc.
The fact is that the Arduino IDE is just an interface to programming in C++ (like Visual Studio for example). The IDE does not make or break you as a programmer.
As a person who has never programmed in their life, if they use nothing else except Arduino's IDE and an Arduino Board, can they claim to be a C++ programmer?
Of course. Just as much as a programmer who has never used anything but Visual Studio to develop on C++ for Windows using Win32 API, can claim to be a C++ programmer. These platform specific API's are nothing but libraries sitting on top of C++. If there were actually some core language level changes for Arduino, then we could argue about it.
Sembazuru:
Thus, Arduino is C++ with some automatically linked helper libraries and header files that add the Arduino flavor at the source code level.
If we're arguing semantics then the Arduino language is NOT C++ - it is a language which is used to generate C++. For all practical purposes you can consider it to be C++, but strictly speaking it is not exactly the same as C++. There is code which is valid Arduino code which a C++ compiler will not compile, and the reverse is also true.
If you learn to write Arduino sketches then most of what you learn will carry across to and from a pure C++ environment, but you will be caught out by the Arduino-specific quirks that affect function prototypes, use of user-defined types in function signatures, references to #included files, and so on.
Can you give an example what code is exactly Arduino specific that C++ compiler isn't able to compile? You do realize that all compilers add keywords to the C++ language that are not part of C++ standard thus per your definition there is no single C++ programmer on the surface of the earth If you can give a single example which is Arduino specific core C++ level language modification, then I'll agree with you. Simply having an IDE which adds some libraries to the argument list passed to the linker doesn't define a new language.
As a person who has never programmed in their life, if they use nothing else except Arduino's IDE and an Arduino Board, can they claim
to be a C++ programmer?
Yes of course. However without further education they won't know what functions are part of the fundamental C++ language compiler and what functions were written by the arduino folks to make programming some AVR chips easier for beginners. For example the AnalogRead() function is not a built in function of the C++ language but it is written in C++ and made available to the 'arduino programmer'.
Yes of course. However without further education they won't know what functions are part of the fundamental C++ language compiler and what functions were written by the arduino folks to make programming some AVR chips easier for beginners.
This is true in any C++ programming environment though and not specific only to Arduino.
Yes of course. However without further education they won't know what functions are part of the fundamental C++ language compiler and what functions were written by the arduino folks to make programming some AVR chips easier for beginners.
This is true in any C++ programming environment though and not specific only to Arduino.
cjdelphi:
As a person who has never programmed in their life, if they use nothing else except Arduino's IDE and an Arduino Board, can they claim
to be a C++ programmer?
Would a guy who's only done Arduino, and he's really good at it, be honest to thereby claim "knowledge of C++" or "familiarity with C++" on his resume/C.V. ?
As a person who has never programmed in their life, if they use nothing else except Arduino's IDE and an Arduino Board, can they claim
to be a C++ programmer?
If you can program Arduino then you can do some C++ code.
Arduino as I understand is the development tool, hardware standard and trade name, not a language.
Besides that most programs I've seen here on the dutch arduino forum are just C programs. And it's noticable that documenting programs seems a big problem for a lot them. As for a good programmer definition..... After 35 years of programming, this discussion keeps popping up
My personal view of a good program is one which is written for the guy who has to maintain it for the next years. So ask him or her
I once met a guy who I worked with 15 years earlier at Exxon. He told me that my programs were still running without any defects (was a sales statistics system). One of the reasons was the excellent documentation and and tidy programming. Are they brilliant technical designed solutions(which nobody understands afterwards)? probably not. But they are stable and maintainable.
my 2 cents
"The microcontroller on the board is programmed using the Arduino programming language (based on Wiring) and the Arduino development environment (based on Processing)."
"The Wiring IDE comes with a C/C++ library called "Wiring", which makes common input/output operations much easier. Wiring programs are written in C/C++, although users only need to define two functions to make a runnable program" (Wiring in Wikipedia).
My emphasis. It's like if you were programming for OpenGL, and claim it's not C++ because OpenGL isn't part of the language. If there are actual changes to the language syntax it's a different deal of course, but until now I have only seen C/C++ API's exposing Arduino functionality.
JarkkoL:
Can you give an example what code is exactly Arduino specific that C++ compiler isn't able to compile?
Most Arduino sketches cannot be compiled as-is by a C++ compiler. They need the mucking-about that the Arduino IDE performs to turn it into valid C++ before they can be compiled. The changes are relatively minor - adding some function prototypes, adding some standard #include files, moving files around so that <> and "" #include file references don't work quite the same in Arduino as in any other C++ environment. You can look at the generated C++ code for yourself to see what the changes are.
The changes are not huge and given a snippet of code it would be hard to know whether it was Arduino or C++, but still the distinction is there. The Arduino programming language is so close to C++ that for all practical purposes you can just treat it like C++, but it's not quite C++.