C++ Help Forum
Ancalagon wrote:
I'm not a C++ person, but I'm about 99.9% sure that C++ can make C function calls without any more effort or overhead than C itself.
It would be really, *really* dumb if a language with a 100% C-compatible subset couldn't just call a C function.
It would be really, *really* dumb if a language with a 100% C-compatible subset couldn't just call a C function.
That would be a logical assumption, but C++ isn't all that logical. It would seem that you should be able to typecast the function somehow and force it to make a real C call, but all of the win programs I have seen in C++ have had some kind of helper library attached to them (.net, mfc,etc). While it may be presumptuous to say that it can't be done without libraries, the fact is that there doesn't seem to be anyone actually doing it.
n4mwd wrote:
That would be a logical assumption, but C++ isn't all that logical.
I looked it up: "C++ can use the same function call and return sequences as C" --Bjarne Stroustrup, The C++ Programming Language, 3rd Edition.
_________________
"A dead thing can go with the stream, but only a living thing can go against it." --G. K. Chesterton
t0
Veteran
Joined: 23 Mar 2008
Age: 51
Gender: Male
Posts: 726
Location: The 4 Corners of the 4th Dimension
n4mwd wrote:
Then enlighten me please. Windows requires a C/PASCAL function call. C++ calls don't work. Without making C style calls, how would C++ do this?
What are you talking about? Are you honestly saying that C++ calls don't work in Windows without some kind of special library? If so, you're wrong.
There is a large portion of the Win32 API that requires either the cdecl or pascal calling convention. Most of these are native C functions and their calling conventions are defined as such in their respective header files. For example:
Code:
int PASCAL FAR closesocket ( IN SOCKET s);
or
Code:
HRESULT __cdecl Initialize (void);
Since this is in the header file, the compiler can build the function call rather than having to do it at run-time. That means the C++ compiler can build the function call exactly the same as the C compiler which should yield equal efficiency.
I'm also not sure why you're grouping "C/PASCAL" since their calling conventions are totally different.
Similar Topics | |
---|---|
New to the forum and the reality of ASD |
02 Jan 2025, 7:01 pm |
new today so glad to have found this forum |
01 Nov 2024, 10:10 am |
forum post likely to increase polarization |
28 Dec 2024, 12:54 pm |