|
Now I am totally lost.
I thought overloading was having same function name with different types of variables.
Such as
function(int)
function(void*)
function(double)
That works fine in Arduino C++ compiler.( And right now I have a bug in my code because I am using it).
I am assuming Arduino compiler is C++, did not really try to find out.
But since it works with classes....it must be C++ based.
Cheers Vaclav
|
|
|
|
|
Vaclav_Sal wrote: I thought overloading was having same function name with different types of variables. Such as function(int) function(void*) function(double) You thought right.
Vaclav_Sal wrote: That works fine in Arduino C++ compiler
As it should: after all is a C++ compiler.
You have to understand that C and C++ are two different programming languages. While C++ supports function overloading, C does not.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
The following defintion is implied overloading since you can call it in one of two ways.
function(int a, int b = 0);
function(1, 2);
function(1);
|
|
|
|
|
OK, I did try this
void TestFunctionA (int a, int b = 100)
{
a += 1;
b += 10;
Serial.print(b);
}
void TestFunctionB (int a)
{
a += 1;
// b += 10;
Serial.print(a);
}
and calls
TestFunctionB (10); // int a, int b = 100)
TestFunctionA(10,234);
And the compiler said too many arguments in function call
But if I change the b to float it compiles and it does makes sense to me. Partially.
If the b parameter b is not passed, than the function A will be executed and compiled.
Confusing, yes.
But that was not the reason I asked. In "real" C compiler when a parameter is declared optional the code will compile without having to change all function calls to include the optional parameter.
But I still do not know if that is ANY standard or just MS compiler specific.
But Arduino compiler expects the "optional" parameter, so it is really not optional.
Cheers Vaclav
|
|
|
|
|
That does not make any sense at all, you are using two different functions.
|
|
|
|
|
Whoops
I was trying to demo a point and messed it up adding the A and B to the functions.
|
|
|
|
|
It is always best to write and test your code, and then use copy and paste to show exactly what the issue may be.
|
|
|
|
|
This doesn't compile as C code in VisualStudio 2010. If it did for you, you compiled as C++.
Hint: in VS 2010 you can't create a C project directly, only a C/C++ project that will contain *.cpp files which by default will be compiled as C++. You can override that behaviour by explicitely forcing C compilation in the Compiler->Advanced settings tab of the project. Or you can put your C code in a *.C file (that you will have to explicitely create, of course).
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Since C doesn't allow overloading to start with, the only way to call a function with alternate sets of parameters is by thinking up a pattern on how you pass these parameters in a less rigid way.
One way has already been mentioned: passing an array of void pointers. The disadvantage is that you have to figure out what is what, including type, and if more than one parameter is optional you need to additionally pass some information about which of the parameters were skipped.
Pretty much the same goes for vararg lists.
A slightly better approach that offers strict control over types and meaning of parameters is passing a struct that contains all possible parameters: write one function that allocates and/or initializes the struct with defaults, and in the code overwrite all values that you want different, then pass the struct to your processing function. If you have mandatory parameters without sensible defaults (e. g. array sizes), make sure to pass these to the intialization function.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTestFindWindowDlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' .
While Iam Doing Broadcasting Message For Multiple Instance.......?
Can Anyone please Help me out?
|
|
|
|
|
You've declared the function with a void return type.
Change that to return an LRESULT .
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
Thanks Vrry Much For Resolving the error...... Superman_
|
|
|
|
|
#ifndef _MFCC_DEFINES_H_
#define _MFCC_DEFINES_H_
#define PI 3.1415926536
#define framesize1 20
#define frameshift1 10
#define DFT_POINT 1024
#define NUM_OF_FILTER 22
#define NUM_OF_COEFFICIENTS 13
#define NUM_OF_GAUSSIANS 1024 /*1024=POW(2,NODES)*/
#define NUM_OF_MIX 512
#define TOTAL_MODEL 13312 /*13312=NUM_OF_GAUSSIANS*NUM_OF_COEFFICIENTS*/
#define EPS 0.01
#define THRESHOLD 0.01
#define NODES 10 /* Total no of nodes******/
#define NUM_OF_SPEAKERS 30
#define FILE_NAME_LENGTH 30
#define SPEAKERIDSTART 9000
#define FIVESPEAKERS 5
#define VALID "V" // Valid
#define INVALID "I" // Invalid
#define CHANNELFLAG 0 // If CHANNELFLAG is 1 Cepstral Mean Substraction will be done.
#define SIZE_FULLPATH 150
#define maxtrain 20 // number of train model
#define maxtest 1000 // number of testing wav file
#define now_test "./"
#define curenttraingtest "./curentlist1.txt"
#define testpath "./"
#define result12 "./result04.txt";
#define SPEECH_NONSPEECH "./speech_nonspeech.txt" // Consists boolean array of size equal to total no. of frames, for a speeched frame value is 1 and for nonspeeched frame value is 0.
#define NO_SPEECH_FRAMES "./no_speech_frames.txt"
#define STARTING_POINT "./starting_point.txt"
#define END_POINT "./end_point.txt"
#define ID_EXTENSION "_AM03MENR" // Common extension to all the speaker ID's. AM03MENR - session(A) OnlineMobile(M03) (M)ultienvironment (EN)glish (R)eading
#define FILE_EXTENSION ".wav" // File name extension for wave file
#define AVR_ENR "./avr_enr.txt"
#define PATH_TEXT "./" // Path to the directory which contains all the text files
#define PATH_TRAIN "/home/ast9/text_independent/recorded_files/train/"// Path to the directory which contains all the recorded training files
#define PATH_TEST "/home/ast9/text_independent/recorded_files/test/" // Path to the directory which contains all the recorded testing files
#define PATH_TEXT_MULTI "/home/ast9/textfiles/" //Path to the directory which contains all the multilevel text files.
#define PATH_COUNT "/home/ast9/textfiles/count.txt" //Path to the directory which contains count.txt file.
#define spechmfcc "./"
char * mfcc_computation(char *id, int, char *fullpath_input, int,int,int,int,int);
#endif
here is the header.h code.
From this if i try to print the NUM_OF_COEFFICIENTS in main program using
coefficients=(details.NUM_OF_COEFFICIENTS);
printf("Num of ceptral coefficients=%d",coefficients);
but error is generating undeclared details.
modified 30-Aug-14 5:58am.
|
|
|
|
|
First you need to create a function pf that takes an integer value and prints it somewhere.
Given this and your other questions, I think you would benefit from studying a decent book on C/C++, or search the internet for some tutorials. You cannot learn C programming by just asking questions on this forum.
|
|
|
|
|
pf i wrote is not function its printf()
|
|
|
|
|
Well it really does not help us if you do not show the exact code that you have a problem with. If you want to learn how to use printf correctly then I suggest studying the documentation[^].
|
|
|
|
|
Please have a watch upon my code ..
|
|
|
|
|
maibam debina wrote: but error is generating undeclared details. That is because you are using a structure or class reference for something that is a simple integer value. It should be just:
coefficients=NUM_OF_COEFFICIENTS;
printf("Num of ceptral coefficients=%d",coefficients);
|
|
|
|
|
Thank you Richard ..hav a nice day
|
|
|
|
|
I can only agree with Richard. I've had a look at some of your questions and found that you're lacking the most fundamental understanding on how to properly write and test a program in C.
Please do yourself and everyone else a favor and use a proper C book or tutorial. One of the first links I found on that topic is this: http://www.cprogramming.com/tutorial/c-tutorial.html[^] . Read that tutorial, take your time to understand what it teaches you. Make sure to actually try out the program snippets. Learn how to set up your working environment: compiler, linker, debugger. Once you've done that you'll save a lot of time because you won't need to ask about such basic problems.
Learning C will take a considerable amount of time. But not learning it properly will cost you even more time in the long run, and others as well!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
This needs to be removed
-- modified 29-Aug-14 12:11pm.
|
|
|
|
|
Not heard of that, and I cannot see what use it is. Why not just run the original in a command window to start with?
|
|
|
|
|
|
I still don't see the point. All of those functions will run perfectly in their own console window so what is the benefit of "It"?
|
|
|
|
|