Weaknessforcats is partially correct, though it has nothing to do with how the function is first called. In C, if you do not specify any parameters, it is equivalent to declaring with an ellipsis. In C++, if you do not specify any parameters, it is equivalent to declaring with void.
- /* in C these are equivalent */
-
void fn();
-
void fn(...);
-
-
/* in C++ these are equivalent */
-
void fn();
-
void fn(void);
-
If you are to declare a function in C without parameters or using the ellipsis[*], it is legal to define the function with any set of parameters you want. So the following is valid, if not dangerous:
- /* in C the following is valid in header file */
-
void fn();
-
/* with the source file defining it like this */
-
void fn(int foo, float bar)
-
{
-
/* do stuff */
-
}
-
It is dangerous because you could do a call to fn() with anything, an int and a float as is required, or just a double or even nothing at all. As you can see, the problem with doing this is that if the function is not passed the correct arguments, the compiler will allow it with no warnings. This is REALLY BAD.
There could be some legitimate reason to do this, but I’m tired and can’t think of one at the moment. However, you may be able to allow for this behaviour. To do this, you would need to use the
extern "C" { ... } syntax. This would be best done in the header file like this:
- #if defined __cplusplus
-
extern "C" {
-
#endif
-
-
// C prototypes here
-
-
#if defined __cplusplus
-
}
-
#endif
-
If you do not have access to modifying the header file you can try the following, I'm pretty sure it should work:
- extern "C" {
-
#include "GraphicsDevice.h" // use <> instead of "" if this is a system header
-
}
-
If this works, fine, but be aware that your header file is a ticking time bomb. If the function is to take a pointer to a NewDevDesc, then it should be put in the C declaration for the function pointer. Otherwise you may inadvertently assign a function to that function pointer which does not take the appropriate parameter. Doing that will cause undefined results such as seg faulting, memory corruption, odd behaviour or if you are extremely lucky, no apparent effect all the time, and if you are unlucky, no apparent effect some of the time.
I would be extremely careful with using this header. I personally hate legacy headers like these and have
personally chastised companies for leaving them in for as long as they have.
Hope this helps.
Adrian
[*]NOTE: I think in the newer C specs (or may be all of them), you cannot use an ellipsis without at least one parameter to indicate how many parameters are actually passes like the format string use for printf().