Could someone knowledgeable in C++ please help with the syntax for the example I provided? Do I need to put it inside a C++ file or it is possible have sections of a C-file containing C++ code?
You can't put C++ code inside a C file, but since C++ is (mostly) a superset of C, most C code will compile without issue. About the only thing you can't do is use a C identifier that is a C++ keyword (e.g. int new; will not compile in C++).
Depending on what you're running on your ARM, you might be able to get C# (mono) up and running on your ARM device (e.g. raspberry pi or similar).
I converted my project to a C++ project (I could see that the line <nature>org.eclipse.cdt.core.ccnature got added inside my .project file) and added your code, but I get the following error message when I try to build the project:
cannot open linker script file -Wl,-Map=output.map: No such file or directory MyProject C/C++ Problem
Nothing that I can see. I just did a build with -Wl,-Map,output.map and it worked fine. But the error message you have suggests that the linker is trying to read -Wl,-Map,output.map as a script file for some reason. I am not sure whether the MCU g++ linker is significantly different from the standard ld linker, but you may want to check the documentation.
It's probably a stupid question, but is there any way to make anonymous function usage like that compile inside a file with .c (not .cpp) extension? I know I'm allowed to put snippets of C-code inside a C++ file, but I suppose the opposite isn't possible (not even with clever macros)?
You have two choices:
1. Your program needs specific argument values which you must check by iterating over the items in argv. The actual number and type is for you to decide.
2. Your program does not accept command line arguments in which case you just ignore them. You may wish to display a warning message if argc is greater than 1.
You did not mention what error you received, but I assume it is because you are still trying to access an item which does not exist. The values for argc and argv are as follows:
1. argv is an array of strings, which will always contain at least one item: the name of the executable that is used to initiate the program.
2. argc contains the number of items in the argv array. So it will always be at least 1.
Let's look at a couple of examples:
1. A simple command line call to run my program, which is called Test.exe produces the following:
If we add some parameters to the command line we will get something like
C:\Users\user1\Documents\Code\C++>Test.exe one two "three and a half"
argc = 4
argv = Test.exe
argv = one
argv = two
argv = three and a half
So argv now contains 4 items, the program name followed by each item that is separated by a space or tab. Not that argv contains four words, since they were delineated by double quotes in the command line.
The code to list these values is as follows:
std::cout<<"argc = "<< argc <<std::endl;
for (int i = 0; i < argc; ++i)
std::cout<<"argv["<< i <<"] = "<< argv[i] <<std::endl;
Generally you are not interested in the program name so you can start the above loop from 1 rather than 0.
The actual values in each parameter are for you to decide. You can use simple strings in a specific or random order, option letters or names preceded by single or double dashes or forward slashes:
Test check \foo\bar\filename.txt
Test -c C:\user1\Documents\file.jpg
Test --check somefilename