Aller au contenu

Photo

default value does not match the initializer


  • Veuillez vous connecter pour répondre
2 réponses à ce sujet

#1
bealzebub

bealzebub
  • Members
  • 352 messages
Hey all, I'm trying to sort out some crashing issues and ran verify on my .mod. It came back with all types of scripts
warning: function "xxx" argument "xxx" default value does not match the initializer value for a previous declaration. The first declaration value will be used.
I don't really understand what this means. Could someone explain?

#2
Loki_999

Loki_999
  • Members
  • 430 messages

When you create a script you can define what is known as a prototype.  Normally you can only refer to a function that is defined prior to the one calling it.  But using prototypes you can can them regardless of their position in the script.

 

The error you are getting is that the prototype does not match the actual function... in other words, someone (the scripter) made a boo boo.

 

Let me give you some examples.

 

This here is normal and will work without a problem.

int AddTwo(int a, int b)
{
 return a+b;
}

void main()
{
 AddTwo(2,5);
}

The AddTwo function is defined before the main function, so main can call it without issue.

 

But instead, we can use a prototype like this.

int AddTwo(int a, int b);

void main()
{
 AddTwo(2,5);
}

int AddTwo(int a, int b)
{
 return a+b;
}

If we hadn't defined the function before main(), then it would not be able to call it, because it wouldn't know it exists (Because main() would be compiled before AddTwo.

 

Now, what sometimes happens, especially when people are defining things in include files and making changes, they forget other scripts need a particular function, and don't think to recompile them, or they don't pay attention to errors.

 

For example, if we have this...

int AddTwo(int a, int b);

void main()
{
 AddTwo(2.0,5.0);
}

float AddTwo(float a, float b)
{
 return a+b;
}

We obviously had decided that we didn't want to add integers but floats. But we forgot about the prototype, and so an error would be thrown, similar to the one you got. Depending on whether the prototype or the actual function has the types it uses to compile (the first declaration) and what values are being passed in the calling function will determine whether the script will work as intended or not.

 

This example would usually be spotted.  Its more likely to be the case as a said earlier when you have include files.

 

For example..

// Include file Add_inc

int AddTwo(int a, int b)
{
 return a+b;
}
// ScriptOne calling AddTwo

#include "Add_inc"

int AddTwo(int a, int b)
{
 return a+b;
}

So, that works.  But then later on, we create a new script ScriptTwo and decide we need floats. So we go to the include and change it to use floats instead.

 

All is then fine with both the old and new scripts (Because ScriptOne was compiled using the old version and ScriptTwo the new version.  But then later, we go back and recompile ScriptOne and bang, we get an error.

 

There is another condition where this can occur.

 

If there are two include files, or an include file and a the calling script, that both define the same function.

 

So in this example, someone made ScriptOne and included two different includes, both of them containing AddTwo.  That will blow the mind of the compiler as well, again, it will default to using the first definition it comes across.

 

So, basically, you have to hunt down the function this error is referring to, and check that you only have a single definition for it that  matches its prototype.



#3
bealzebub

bealzebub
  • Members
  • 352 messages
whew, that's a mouthful, but I understand.
thanks