|
|
In C++ this concept are overloading and overriding
Can i use this concept in C?
modified 16-Jun-16 10:40am.
|
|
|
|
|
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
|
|
|
|
|
|
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
modified 16-Jun-16 12:55pm.
|
|
|
|
|
Wow, never heard about that, before.
|
|
|
|
|
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
|
|
|
|
|
Hi,
I am working on a project in Visual C++ 6.0. I have included the following statements in a file:
#import "C:\Program Files\Common Files\System\ado\msado15.dll" \
rename( "EOF", "adoEOF" )
#import "c:\Program Files\Common Files\system\ado\msadox.dll" \
no_namespace
I am getting the following error:
error C2556: 'enum DataTypeEnum __thiscall ADODB::Field20::GetType(void)' : overloaded function differs only by return type from 'enum ADODB::DataTypeEnum __thiscall ADODB::Field20::GetType(void)'
Any idea why this error is generated...?
How to resolve the above issue...?
Regards,
mba
modified 16-Jun-16 3:44am.
|
|
|
|
|
The definition of that enum exists in two places. You need to check the libraries to see how you can eleiminate one of them. I would guess it may have something to do with the second import using the no_namespace option.
|
|
|
|
|
Richard was spot on ADO and ADOX both use the no_namespace option you need to rename the functions of one into a renamed namespace
#import "..\..\..\dll\msadox.dll"
#import "..\..\..\dll\msado15.dll" no_namespace rename("EOF", "EOFADO")rename("DataTypeEnum", "DataTypeEnumADO") rename("EditModeEnum", "EditModeEnumADO") \
rename("FieldAttributeEnum", "FieldAttributeEnumADO") rename("LockTypeEnum", "LockTypeEnumADO")
You could choose to import the ADO and rename the ADOX functions, rename the one you use least.
In vino veritas
|
|
|
|
|
Dear All,
Below is my Problem Statement.
Currently i am trying to Calculate checksum using File Attribute(File Size) as Checksum input to Checksum Algorithm to get the Checksum hash and i am using the IDE Microsoft VS 2015 C++ for the same
The above said scenario is working fine for me .
It gives me below output and its proper one.
Input : Hello
Hash :f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0
**********************
So, i am trying to replicate the Same thing in Microsoft Visual C++ 6.0 and i am not not able build/Run the project.
and i can see lots of External Dependencies are being referred from Program files.
So,I request the somebody to share the Working piece of code which does SHA1 Checksum validation for the given input in VS 6.0 C++.
I really appreciate if somebody could help me out to resolve the issue.
Thanks,
Goutham KD
|
|
|
|
|
Member 12485116 wrote: ...i am not not able build/Run the project.
and i can see lots of External Dependencies are being referred from Program files. And we are supposed to know what these are?
"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
|
|
|
|
|
Hi.
the external references for Example : wincrypt.h,Cryptohash.h etc.
which reside inside below path.
C:\Program Files (x86)\Windows Kits\8.1\Include\um
there are lot many refereces inside above mentioned headers.
|
|
|
|
|
So if the files reside on your computer (it would be an entirely different problem if you were trying to reference non-existent files), what exactly is the problem?
"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
|
|
|
|
|
I suspect OP's problem may be related to the antiquity of VC6.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Hello All,
Just let me know On how to Add External dependencies in VS 6.0 C++ project.
Thanks.
|
|
|
|
|
External dependencies are libraries or object files. They can be added in the project settings at Properties - Linker - Input - Additional dependencies (not quite sure for VC6 but should be). Specify the full path. Optionally add the path(es) at Properties - Linker - General - Additional library directories. Then you can specify the plain name.
The functions exported by libraries are declared in header files. These must be included in the source and header files that use declarations from those header files. Like with library directories you can avoid specifying the path in the include statements by adding the directories to the project settings (Properties - C/C++ - General - Additional include directories; again not sure with VC6).
|
|
|
|
|
I have doubts this will work the 8.1 kit code is expecting v120XP platform toolset and linking. It will be really interesting to see if it does work.
Is there a reason you can't just download and install VS2015, something funky with the code?
In vino veritas
|
|
|
|
|
Possibly, but I still use it too.
"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
|
|
|
|
|
I am new to C++ I want to define my functions declaration in a seprate header file and definitions in 2 different header files. I am saving the file with .h and .c extension in same folder where main file is located too. I also know that I have to use double quotes to include my files in main. However, I am unable to find the way to define my header file for definitions and declaration. Please give me a small example so that I can get idea about it
|
|
|
|
|
It should be avail able on any tutorial on the net but lets do a basic.
The header file .h is where you put anything that needs to be accessed from another unit. Your functions etc are just prototype declarations. You generally put a guard #ifndef around it to stop it being included multiple times if called from multiple units.
So "mycode.h" would be something like
#ifndef _MYCODE_
#define _MYCODE_
#define DEV_OK 0 // No device error
#define DEV_ERROR -1 // Device access error
void MyFunction1 (int someValue);
int MyFunction2 (void);
#endif
Now for the body file MyCode.cpp
#include "mycode.h"
int CurrentValue = 0;
void MyFunction1 (int someValue){
CurrentValue = someValue;
}
int MyFunction2 (void){
return (currentValue);
}
That is all there is to it as a minimalist code sample.
In vino veritas
|
|
|
|
|
Sir please check the following. There is something wrong. If you correct it for or highlight any improvement factor it will be appreciated.
Header File:
#ifndef _CALCULATION_H
#define _CALCULATION_H
#include "calculation.cpp"
#include "getinput.cpp"
void input_Func(void); void input_Area(void); void input_Trap(void); float rectangle_Area (float , float); float trapezoid_Area (float , float, float);
#endif
Calculation File:
#include "calculation.h"
float rectangleArea (float width, float length)
{
float Area_Rectange = 0;
Area_Rectange = width * length;
return (Area_Rectange);
}
float trapezoidArea (float base1, float base2, float height)
{
float Area_Trapezoid = 0;
Area_Trapezoid = ((base1 + base2)/2) * height;
return (Area_Trapezoid);
}
Input data File:
#include "calculation.h"
void input_Func(void)
{
cout << "\n\nEnter 1 to calculate the area of Rectangle" << endl;
cout << "Enter 2 to calculate the area of a Trapezoid" << endl;
cout << "\n\nEnter your choice : ";
cin >> choice;
}
float input_Area(void)
{
float width = 0, length = 0, answer = 0;
cout << "Enter the width of rectangle :";
cin >> width;
cout << "Enter the length of rectangle :";
cin >> length;
answer = rectangleArea(width, length);
cout << "The area of Rectangle is : " << answer << endl;
break;
}
float input_Trap(void)
{
float base1 = 0, base2 = 0, height = 0, answer = 0;
cout << "Enter base1 of trapezoid : ";
cin >> base1;
cout << "Enter base2 of trapezoid : ";
cin >> base2;
cout << "Enter the height of trapezoid : ";
cin >> height;
answer = trapezoidArea(base1, base2, height);
cout << "The area of Trapezoid is : " << answer << endl;
break;
}
Main File:
#include <iostream>
#include "calculation.h"
using namespace std;
int main()
{
int choice = 0;
char tryagain = 0;
do
input_Func();
switch(choice)
{
case 1:
{
input_Area(); rectangle_Area (float , float);
}
case 2:
{
input_Trap(); trapezoid_Area(float, float, float);
}
default:{
cout << "Neither 1 nor 2 entered." << endl;
}
}
cout << "Do you want to do another calculation? : ";
cin >> tryagain;
}while (tryagain == 'Y' || tryagain == 'y');
return 0;
}
Your help to me in right direction will help me to become a good developer in future. I am completely new in this field. My code is working fine if i put everything in main function. Problem is arising when i am separating declaration and definitions 
|
|
|
|
|
The problem is here:
#ifndef _CALCULATION_H
#define _CALCULATION_H
#include "calculation.cpp"
#include "getinput.cpp"
Don't include source files (*.c, *.cpp) using the include statement (especially form within header files).
Also split the header file into two (or three):
- One named calculation.h with the declarations for the calculation.c source file
- One named getinput.h with the declarations for the getinput.c source file
- Optionally one named according to your project name with global declarations used by multiple source files and public declarations for your main.c source file
To build your application each source file must be compiled and the created object files must be aftwerwards linked to create the executable. This is usaully accomplished using a make file. The kind of the make file depends on your development environment. With IDE's you won't see the make file but use options to add source files to your project.
|
|
|
|
|
I would strengthen what Jochen said with you DON'T EVER #include *.c or *.cpp .. NOT EVER ... includes are only .H files. We allow includes to be any sort of file for historic reasons none of which we would ever advise and few programmers would even know.
Please remove these lines they would never be correct anywhere much less where you have them
#include "calculation.cpp"
#include "getinput.cpp"
So with Calculation.cpp you include its own header Calculation.H which you have done ... that's all you need the two files are then linked.
If you need functions in GetInput.cpp then you include GetInput.H which will declare everything that is public from within GetInput.cpp. Do you get it that the .H file limits what you can access as a public everything else in the .CPP is hidden which is the whole point of doing it. You are trying to restrict the chance of making errors by allowing only access to the unit in the way you want. That is why you publish only what you want to allow access to on the interface of the .H file.
In your case Calculation.H doesn't need to know about GetInput.cpp, even if you did need it then you include GetInput.H
So if calculation.cpp needs to know about GetInput.cpp then simply include GetInput.H within calculation.cpp
You seem to be over thinking it
In vino veritas
modified 13-Jun-16 5:06am.
|
|
|
|
|
Thank you everyone for your reply. Can you post in the code form like i showed in my 2nd post. If any link available about explaining this thing please share with me
|
|
|
|