Can define a function with same name and signature?
-
In C++ this concept are overloading and overriding Can i use this concept in C?
-
In C++ this concept are overloading and overriding Can i use this concept in C?
What would the purpose be?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
In C++ this concept are overloading and overriding Can i use this concept in C?
-
In C++ this concept are overloading and overriding Can i use this concept in C?
Yes you can but if you want to do it statically it has to be done via compiler directives and smart macros and it's used by embedded programmers in some specific situations. It is not something we encourage to use like the C++ feature but there are times it is the only way to achieve what is needed. It has been improved and is portable and easy if your compiler accepts the C11 standard word "_Generic". Here is a reasonable link on it Rob's Programming Blog: C11 - Generic Selections[^] You can see the general form of the macro which provides the overloading
#define acos(X) _Generic((X), \
long double complex: cacosl, \
double complex: cacos, \
float complex: cacosf, \
long double: acosl, \
float: acosf, \
default: acos \
)(X)As the C community is still one of the larger programming languages the standard has been altered over time. In time order the main standards are C87, C90, C99, C11. Microsoft and Visual Studio has been one of the slowest compilers to include the new standards. Visual studio 2013 was the first version to cover most of C99 but it has been available in GCC and many micro-controller C compilers for many years.
In vino veritas
-
Yes you can but if you want to do it statically it has to be done via compiler directives and smart macros and it's used by embedded programmers in some specific situations. It is not something we encourage to use like the C++ feature but there are times it is the only way to achieve what is needed. It has been improved and is portable and easy if your compiler accepts the C11 standard word "_Generic". Here is a reasonable link on it Rob's Programming Blog: C11 - Generic Selections[^] You can see the general form of the macro which provides the overloading
#define acos(X) _Generic((X), \
long double complex: cacosl, \
double complex: cacos, \
float complex: cacosf, \
long double: acosl, \
float: acosf, \
default: acos \
)(X)As the C community is still one of the larger programming languages the standard has been altered over time. In time order the main standards are C87, C90, C99, C11. Microsoft and Visual Studio has been one of the slowest compilers to include the new standards. Visual studio 2013 was the first version to cover most of C99 but it has been available in GCC and many micro-controller C compilers for many years.
In vino veritas
-
In C++ this concept are overloading and overriding Can i use this concept in C?
Well, Nearly per Definition you can Not use a C Compiler to compile CPP! You do not understand where it all came from, but I'll ex[plain. 'C' was created by Brian Kernigan and Dennis Ritchie as a High Level Language, with the flexibility of Assembler. It has a straight forward flat language structure, needing a very simple symbol table. (The Symbol Table is a database used by the Compiler, to keep track of what symbolic value is stored where) This database would not allow for items like 'MyStruct.MyMember'.Instead, it kept a separate Database of Structure Names. When Brian Stroustrep started CPP, it was initially a 'PreCompiler' which would write a 'C' acceptable set of variable names. For Intance: void MyStruct::MyFunct(int,char,int) would be translated into something like 'FnMyStruct_MyFunct_int_char_int__void' and then let the 'C' Compiler do it's Job. That worked of a kind, but, what if one also were to write a 'C' function: 'FnMyStruct_MyFunct_int_char_int__void(int Param)' Unlikely, but, a potential problem. Brian Stroustrep had to use symbols and characters acceptable to the 'C' language. When proper CPP Compilers appeared at the scene, the decoration became more flexible. For Instance: 'FnMyStruct?MyFunct??int_char_int???void' Such a name cannot be passed as a 'C' Name. (Note: I do not state that the scheme here is actually used, it is just an illustration to explain the point of how a CPP Compiler generates different code compared to a 'C' compiler) A CPP compiler can compile 'C' Code. The otherway around, a 'C' Compiler accepting CPP Code is never going to happen, for the reasons stated above. Now, As others have Asked: what is your problem! Perhaps you want to Include a 'C' Module in your 'CPP Project' :)
Bram van Kampen