Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 4 months ago.
How to write a function with mbed in C
Hello, I wrote you because I will wish to write a function to my program but I do not know how. For example if I want to do sommen 2 numbers a and b , but using a function. do you know how to proceed ? Thank you for your answers
1 Answer
9 years, 4 months ago.
read the c++ tutorial, this is the easy way http://www.cplusplus.com/doc/tutorial/
if you really need to write a C function within a C++ main program as Mbed, you may use google "call c function within c++" or look at the Mbed source code, because most of the code is C
One answer is http://www.thegeekstuff.com/2013/01/mix-c-and-cpp/
https://www.google.fr/#q=c+tutoriel
posted by Andy A 19 May 2015yes I have also followed a tutorial , but apparently the way to do that with mbed is different from that C
posted by AGON Juppé 19 May 2015It is not, it is identical. Mbed = C++. Which supports all normal C functions also. (If you name a file .c it will be really compiled as C, but then you cannot use mbed library functions).
posted by Erik - 19 May 2015Perhaps you can post a short example of what you have tried so that those offering help can offer alterations.
posted by Stephen Paulger 19 May 2015Well now I'll Explain . I am writing in June " fonction_dwell " function that mite afford to Calculate stay according to an alpha ratio ( stuff pour saver lines of code ) and Make a function call in my main function. Here's how I wrote my fonction_dwell .
but it does not work
posted by AGON Juppé 19 May 2015Realise that you are printf 'dwell' variable (may you want to show 'calcul' variable?). However:
1 - Needless ';' of the function: int fonction_dwell(alpha)
2 - You need to specify the type of variable you pass into the function (int fonction_dwell(float alpha))
code changes
You're right Completely .The power walking . I'll be able to create other functions and move forward. I wanted to ask you , how can I make the call to the function that I just created in my main program?
posted by AGON Juppé 19 May 2015I wanted to ask you know how to make a function call ? This est'à'dire I want utilser a function that already ja create and put it in another program.
posted by AGON Juppé 19 May 2015